top | item 33146378

(no title)

uup | 3 years ago

ts-node isn't an official part of the TypeScript project. It has notoriously bad module support.

Try this:

    // tsconfig.json
    {
      "compilerOptions": {
        "outDir": "dist",
        "module": "es2020",
        "allowJs": true
      },
      "files": ["index.ts"]
    }

    // index.ts
    import('./test.mjs').then(console.log)

    > npx tsc && node ./dist/index.js
    [Module: null prototype] { Foo: [Function: Foo] }

discuss

order

kuramitropolis|3 years ago

I'm not even talking about the module support. (It just seems to have the default support of TypeScript.)

Yes, it imports the module. No, it doesn't do even basic type inference (knowing that Foo is a class and consequently allowing it to be used as a type name) - which it would, if it was a superset of JS. Instead it seems to import everything as "any", which is... a start, I guess?