writing type safe javascript module, with version string abstracted away to manage versions easily
const preact = "preact@10.24.3"
const { h, render } = await import(`https://esm.sh/${preact}`)
const { computed, effect, signal } = await import(`https://esm.sh/@preact/signals@1.3.0?deps=${preact}`)
console.log(`preact version is ${preact}`)
What shortcomings exist with current approaches?
What workarounds are you using in the meantime?
due to type check not working in above example, version string has to be duplicated, which might cause bug when naively regex-replacing.
import { h, render } from "https://esm.sh/preact@10.24.3"
import { computed, effect, signal } from "https://esm.sh/@preact/signals@1.3.0?deps=preact@10.24.3"
console.log("preact version is preact@10.24.3")
π Search Terms
dynamic import constant string infer type any
β Viability Checklist
β Suggestion
statically analyze type of dynamic import if path is statically analyzable, such that
as type of
polars
is"nodejs-polars"
, notstring
, typescript should treatimport("nodejs-polars")
the same asimport(polars)
.π Motivating Example
https://github.com/denoland/deno/issues/26965
Playground Link
π» Use Cases
writing type safe javascript module, with version string abstracted away to manage versions easily
due to type check not working in above example, version string has to be duplicated, which might cause bug when naively regex-replacing.