tapjs / tsimp

https://tapjs.github.io/tsimp/
Other
494 stars 11 forks source link

Are import attributes supported? #27

Open bennycode opened 2 weeks ago

bennycode commented 2 weeks ago

TypeScript 5.3 supports import attributes, but when I execute the following code, I don't see anything on my terminal:

import diags from '../examples/dump-1724954858848.json' with {type: 'json'};

console.log(diags.length);
console.log(diags.map(diag => diag.code).join(', '));
TSIMP_DIAG=error node --import=tsimp/import ./src/main.ts

When I use ts-node instead, printing works fine:

node --no-warnings=ExperimentalWarning --loader ts-node/esm ./src/main.ts
mdmower-csnw commented 2 weeks ago

@bennycode - it seems to work ok for me.

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "resolveJsonModule": true,
    "strict": true
  }
}

package.json

{
  "type": "module",
  "devDependencies": {
    "@types/node": "^20.16.4",
    "tsimp": "^2.0.11"
  }
}

my.json

{ "msg": "hello world" }

index.ts

import myjson from './my.json' with {type: 'json'};
console.log(myjson.msg);

Run it

> node --import=tsimp/import .\index.ts
hello world
(node:8044) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

I did run into some cache issues (probably related to #20), but this got things working again:

> npx tsimp --clear
tsimp: daemon stopped
tsimp: cache cleared