rttist / examples

Set of examples in React, Angular, vanilla TS, Webpack, Parcel, Rollup etc. with configured reflection.
MIT License
0 stars 2 forks source link

TS 5 #4

Open mindplay-dk opened 1 year ago

mindplay-dk commented 1 year ago

I attempted switching from TS 4 to 5, which also means switching from ttypescript to ts-patch.

https://github.com/rttist/examples/compare/main...mindplay-dk:ts-patch-with-ts-5

It doesn't work, and it's not clear to me why it worked before this change.

Looking into node_modules/rttist, the package.json has no type, so node should default to commonjs.

And all of the modules in the dist folder do appear to be commonJS modules with import/require statements.

The problem appears to be typelib/index.js which contains an export {} placeholder - but since the package is a CommonJS package, I don't think export is allowed?

At least that's what the error message appears to suggest to me:

> start
> tspc && node dist/index.js

[INF] tst-reflect-transformer Detected project root: /home/mindplay/workspace/examples/vanilla-typescript-tsc  
/home/mindplay/workspace/examples/vanilla-typescript-tsc/node_modules/rttist/typelib/index.js:6
export {};
^^^^^^

SyntaxError: Unexpected token 'export'

I don't even know if rttist itself is ready for TS 5, so I might be wasting my time here. 😅

I was just curious to see if that would work.

Hookyns commented 1 year ago

I didn't test it with TS >= 5.0 but I think it will not work because they changed compiler API a little. New typegen-based system is based on TS 5.1 and I had to fix almost 100 errors after pluging current Alpha source files in, but it were mostly type errors, so there is a small chance it will work.

The problem appears to be typelib/index.js which contains an export {} placeholder - but since the package is a CommonJS package, I don't think export is allowed?

It is not allowed in .js file at runtime in CommonJS environment but that file shouldn't be loaded. import 'rttist/typelib'; is just a placeholder. TypeScript compiller should only load the .d.ts file (export {} in d.ts file should be fine) but it should never load the .js file, it should be replaced by the metadata typelib file import, so it probably did not happen so that's why it ends with this error.

EDIT: You can try to manually modify the typelib/index.js file in node_modules/rttist folder. Then we'll se if it is rly an issue or not.

EDIT2: BTW, I do not plan to do any changes in the current Alpha version because of new versions of TS, Webpack etc. I'm working on the typegen version and it goes pretty well so far; I think I'll be able to publish first prototype in a week or two.

mindplay-dk commented 1 year ago

Okay, cool, I think I'll just sit tight until then, let you get on with it. 😄

Looking forward to test the next version!