Search code examples
typescriptstripe-paymentsdeno

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:stripe@14.12.0'

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:stripe@14.12.0"
  }

VS Code's settings.json:

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

Why?


Solution

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

    // deps.ts
    export { Stripe } from "npm:stripe@14.12.0";
    

    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.