News for hackers. Stuff that matters.
Re:TypeScript is now officially 10 years old by kuramitropolis on Sunday October 09, 2022 @07:25PM (#33146275)
Okay...

    $ echo "export class Foo { a = 1 }" > test.mjs

    $ npx ts-node
    > import('./test.mjs').then(console.log)
      error TS7016: Could not find a declaration file for module './test.mjs'. '/home/user/Lab/test.mjs' implicitly has an 'any' type.

    $ npx ts-node -O '{"allowJs":true}'
    > import('./test.mjs').then(console.log)
      Promise { <pending > }
      Error [ERR_REQUIRE_ESM]: require() of ES Module /home/user/Lab/test.mjs not supported.

    $ echo "module.exports.Foo = class Foo { a = 1 }" > test.cjs

    $ npx ts-node -O '{"allowJs":true}'
    > const { Foo } = require('./test.cjs')
    > Foo
      [class Foo]
    > new Foo
      Foo { a = 1 }
    > function bar (foo: Foo) {}
      TS2749: 'Foo' refers to a value, but is being used as a type here. Did you mean 'typeof Foo'?
No I did not, TypeScript, and that's about as much as it seems to interoperate. I guess in some cases practical migration might be viable - but as for the general case, the out-of-the-box experience seems to speak otherwise.

It's not even viable to write in JS and manually write a DTS - no way to check em against each other. Except idk library in JS, test suite in TS anyway. So not a lot of lateral movement possible in practice.

Re:TypeScript is now officially 10 years old by uup on Sunday October 09, 2022 @07:44PM (#33146378)
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] }
Re:TypeScript is now officially 10 years old by kuramitropolis on Sunday October 09, 2022 @09:05PM (#33146802)
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?