I am new to Deno and I am figuring out the import map feature. Currently, my import map for express looks like this:
"imports": {
"express": "npm:express@4.18.2"
},
And I am importing express into my project like this:
// @deno-types="npm:@types/express@4.17.15"
import express from "express";
The code runs just fine but I find it a bit annoying to have to import the typing in every file I want to use the express module in. Is there a standard way in Deno to import the typings in one place and not have to reference them directly in individual files?
That's considered an antipattern especially in Deno, and I'm not sure if that's even possible to achieve. Deno's philosophy is to make everything explicit and easy to analyze, debug and backtrack.
By omitting the import
, you would:
express
identifier comes fromexpress
import anymore. If you have another dependency that also exports a member called express
, things could start to become confusingAlso, as of September 2023, Deno is able to autoimport dependencies. For example, in VSCode, if you reference something that is not imported in your file, Deno is able to detect it and add an import
statement automatically for you.