Adding Typescript declarations?
Hey! :)
Are you perhaps interested in adding Typescript declarations or, even, migrating the repo to Typescript? It is not that big, so I think it could be done? You even already have the JSDoc declarations eheh
Thanks in advance!
As an added note, this would make it easier to eventually port this library to AssemblyScript, so we can compile this down to WASM so it can run fast :)
Hi Filipe,
The simulation package has extensive TypeScript type annotations using TypeScript's JSDoc support (https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html).
Type checking should work out of the box when imported into a TypeScript file and can be enabled in JavaScript files in editors that support it (like VSCode) via a // @ts-check annotation or project-wide with a jsconfig.json file (https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html).
If you are interested in performance optimizations, there are things that would likely have a larger impact and also be simpler than porting to a different language. For instance, implementing an adaptive step differential equation solver would be a great project. The simulation package uses a task scheduler for its solvers, so the foundation is already there for dynamic step sizes.
Type checking should work out of the box when imported into a TypeScript file
Hmm it isn't for me, but that be my fault with setup I have (default Next.js with TS).
As for performance, that would indeed be cool to implement :) I have one some adaptive-step solvers in Julia, but have no clue how to implement them, though. It can a future project.
Thanks for checking. I took a look and the type information doesn't work with the Next starter for me either.
Can you try navigating to the simulation folder in your node_modules and run:
npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
(https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html)
And then change the exports key of the simulation package.json to:
"exports": {
".": {
"types": "./types/api/Model.d.ts",
"import": "./src/api/Model.js",
"default": "./src/api/Model.js"
}
},
Let me know if that fixes it for you.
@scottfr it did fix it :) Thank you!
Glad to hear it! I'll add a version of this to the next release.