lenis
lenis copied to clipboard
add typescript declaration file
👋 Hi! Thanks for starting this super cool project. I'm looking to use this in a personal TypeScript project and thought this might be a helpful addition.
This PR adds a process to automatically generate TypeScript declaration files.
Changes
- adds
typescript
dev dependency - adds a new script named
build:types
that generates alenis.d.ts
file containing type definitions using the emitDeclarationOnly option (reference) - adds
"types"
property in package.json (reference) - adds "ts" badge to detail page on npm package registry (reference)
Future Improvements
- To make the automated types more detailed,
JSDoc
type annotation comments could be added to the source code. For example:/** @type {(t: number) => number} */ this.easing = easing;
- It would also improve VS Code Intellisense suggestions within JavaScript files (reference)
Alternatives
- If this doesn't feel like a good direction for the project, an alternative would be to add this to the DefinitelyTyped project instead
@zachkrall is attempting to deploy a commit to the Studio Freight Team on Vercel.
A member of the Team first needs to authorize it.
Would love to see this merged!
Just thinking out loud but why don't translate the code itself to typescript? Probably would be slightly (very slightly) haevier but would benefit also it of typescript and types declarations.
Hi, i'm not conviced about using TypeScript to be honest, I personaly never use it and i'm scared it can slowdown future improvements of the lib. Is it something really necessary ? However I will try to use it on another branch to see how it's working. I'll let you know.
Well actually Typescript is definitely not necessary but it allows the developers to have a more strict type check of javascript at build time which is amazing.
Let's say that helps us to write better code and pervent types related bug during the development.
I don't see any future slowdown
since is totally arbitrary how much use it and by default it doesn't import any overhead to the project.
Theoretically you could just rename the files form .js
to .ts
(and create the building tool) without any code change. Let me know if you need anything in your "typescript test" branch.
+1 for Typescript support—it's my biggest pain point with using Lenis so far. Might be slow at first, but it will make development faster in the long run with autocompletion and inferences.
I think it would also result in less issues being flagged by users since inference and autocomplete would catch 90% of mistakes.
Would it be possible to merge these typescript types as an intermediary solution for folks using the library now? I'm currently having to copy these files into my project manually 😅
If the library is ever rewritten into Typescript, it's easy to delete these declaration files.
We're planning to add types but not to convert the source to TypeScript for now.
@clementroche is this PR a helpful start?
This PR has been merged and pusblished in v0.2.11, can you check if everything is good for you ?