Skip to content

Associate import map @types/<entry-name> entry as types for <entry-name>? #292

Closed as not planned
@dsherret

Description

@dsherret

It's annoying to have to specify stuff like // @deno-types="..." /> above an import (ex. for a npm:@types/... package) and sometimes it's not possible to specify it (ex. with jsxImportSource: denoland/deno#18203).

Perhaps for any import map entry, deno_graph should try to resolve a corresponding @types/<entry-name> when resolving the types of a module. For example:

// deno.json
{
  // ugh, import maps are painful
  "imports": {
    "react": "npm:react@18",
    "react/": "npm:/react@18/",
    "@types/react": "npm:@types/react@18",
    "@types/react/": "npm:/@types/react@18/",
  }
}

Then when a user imports react or react/jsx-server this would get the corresponding types.

This would also not be npm specific and allow for mapping to non-npm types like:

{
  "imports": {
    "react": "npm:react@18",
    "react/": "npm:/react@18/",
    "@types/react": "./@types/react@18/mod.d.ts",
    "@types/react/": "./@types/react@18/",
  }
}

Import map unfurling

This introduces some complexities when unfurling import maps, but I don't believe it would be too bad because we could inject a // @deno-types="..." comment above the import/export.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions