Oleg
Oleg

Reputation: 692

How to get types to work in Deno when using import maps?

For some reason, types do not seem to work properly in Deno (version: 1.41.0) when using import maps.

This works:

import Stripe from 'npm:[email protected]'

Screenshot from VS Code: enter image description here

This doesn't work:

import Stripe from '$stripe'

or

// @deno-types="npm:@types/stripe"
import Stripe from '$stripe'

Screenshot from VS Code: enter image description here

The import map in deno.json:

  "imports": {
    "$stripe": "npm:[email protected]"
  }

VS Code's settings.json:

{
  "deno.enablePaths": [
    "./"
  ],
  "deno.enable": true,
  "deno.unstable": true,
  "deno.config": "./deno.json",
  "deno.lint": true,
}

Why?

Upvotes: 0

Views: 634

Answers (1)

Oleg
Oleg

Reputation: 692

I have resorted to using deps.ts (as described here) instead of import maps, e.g.:

// deps.ts
export { Stripe } from "npm:[email protected]";

and then importing any given dependency like this:

// e.g. stripe.ts
import { Stripe } from "./deps.ts";

Everything works as expected when using this pattern and the overall DX is satisfactory.

Upvotes: 0

Related Questions