Definitelytyped types for system-node.cjs
tbrannam opened this issue · 1 comments
tbrannam commented
- SystemJS Version:
- Which library are you using?
- system.js
- s.js
- system-node.cjs
- Which extras are you using?
- AMD extra
- Named Exports
- Named Register
- Transform
- Use Default
- Global
- Dynamic Import Maps
- Are you using any custom hooks?
Question
I am uncertain where to raise this issue, as npm package @types/systemjs
is not maintained here, but was hoping that @joeldenning would have visibility here.
When building for a Node target, and and importing system-node.cjs, and including @types/systemjs
as a dependency.
import SystemNode from 'systemjs/dist/system-node.cjs'
Then systemjs/dist/system-node.cjs
it not recognized as a typescript module and is untyped. Additionally the Typescript types that do exist do not include applyImportMap
which is only available in system-node.cjs
.
Are there examples that could be cited which demonstrate the usage of TS types with system-node.cjs
?
tbrannam commented
So the simplest thing I could come up with looks like this in a local file
system-node.d.ts
/// <reference types="systemjs" />
declare module 'systemjs/dist/system-node.cjs' {
type SystemJS = typeof System & {
constructor: new () => SystemJS
}
const _System: SystemJS
export { _System as System }
export function applyImportMap(
system: typeof System,
importMap: System.ImportMap
): void
}
// if using Webpack and referencing the module context in a SystemJS Module
declare const __system_context__: System.Context
and usage wise
import SystemPkg from 'systemjs/dist/system-node.cjs'
const { System, applyImportMap } = SystemPkg
const anotherSystemInstance = new System.contructor()
applyImportMap(anotherSystemInstance, { /* importmap *? })