rose-lang / rose

Composable autodiff for the interactive web.
https://rosejs.dev
MIT License
22 stars 0 forks source link

Make TypeScript consumption easier #101

Open samestep opened 1 year ago

samestep commented 1 year ago

Currently the npm package doesn't show the "TS" icon to indicate that it has type definitions, despite having them; judging from this Stack Overflow thread, this seems to be caused by our package.json files not having a "types" field. If you install Rose in a fresh project and try to import it, TypeScript gives this error:

Cannot find module 'rose' or its corresponding type declarations.

As described in the top answer of that Stack Overflow thread, you can resolve this error on the client side via this tsconfig.json:

{ "compilerOptions": { "moduleResolution": "Node16" } }

However, we should probably configure Rose itself to work properly with TypeScript even for users who don't know or don't care to use the more modern module resolution, probably by just setting "types".

Incidentally, if you just use the above in tsconfig.json, TypeScript also complains, due to a recent change in TypeScript 5.2:

Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.

The error can be resolved via this tsconfig.json:

{ "compilerOptions": { "module": "Node16", "moduleResolution": "Node16" } }

We have the same error in our own tsconfig.json files in this repository; it would probably be a good idea to fix those errors, but I don't immediately know how to do that because I don't know what "module": "Node16" actually means as contrasted with "module": "ES2022".