Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definitelytyped types for system-node.cjs #2472

Open
1 of 10 tasks
tbrannam opened this issue Nov 23, 2023 · 1 comment
Open
1 of 10 tasks

Definitelytyped types for system-node.cjs #2472

tbrannam opened this issue Nov 23, 2023 · 1 comment

Comments

@tbrannam
Copy link

  • 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 tbrannam changed the title Definitelytypes types for system-node.cjs Definitelytyped types for system-node.cjs Nov 23, 2023
@tbrannam
Copy link
Author

tbrannam commented Nov 30, 2023

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 *? })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant