-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add TypeScript support #18
base: dev
Are you sure you want to change the base?
Conversation
Thanks for this detailed PR @FabienMotte! There's a few changes I'd like to request and I also have a few questions since I have very little experience with Typescript:
And thanks for spotting the filename pattern issue in the docs where |
I merged some changes into
I also noticed that |
I updated the docs to make the separation clearer between JS and TS. Don't hesitate to put yourself as a reviewer and ask for a change if that's not what you had in mind.
I removed those types, indeed, they are unnecessary.
I guess the answer is yes and would make more sense since Fragment is a JavaScript library. The typing should live on https://github.com/DefinitelyTyped/DefinitelyTyped as Three.js or p5.js are doing. I never published a package on this repo, so I would need to see how this can be done.
No worries, I'll update those accordingly.
Oops, good catch, totally forgot to include this type in the Thank you for your comments! |
Summary
This PR adds TypeScript support for Fragment sketches.
Since Fragment uses Vite behind the scenes (which already supports TypeScript transpilation via esbuild), TypeScript support is pretty straightforward to add.
Result
.ts
extension, for example:fragment ./sketch.ts --new
.-ts
at the end of the template name:fragment ./sketch.ts --new --template=2d-ts
.tsconfig.json
file is created automatically for you with the right paths when you create a new sketch based on a TypeScript template.@fragment/types
. You just need to pass your current sketchrendering
as a generic to lifecycle functions to have the proper types, for example:Init<"2d">
.typedProps
..glsl
,.vs
,.fs
,.vert
, and.frag
).Demo
typescript-demo.mov
Code sample