lenis icon indicating copy to clipboard operation
lenis copied to clipboard

add typescript declaration file

Open zachkrall opened this issue 2 years ago • 2 comments

👋 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 a lenis.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 avatar Sep 17 '22 03:09 zachkrall

@zachkrall is attempting to deploy a commit to the Studio Freight Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 17 '22 03:09 vercel[bot]

Would love to see this merged!

cmalven avatar Sep 19 '22 18:09 cmalven

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.

Valerioageno avatar Sep 24 '22 20:09 Valerioageno

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.

clementroche avatar Sep 25 '22 10:09 clementroche

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.

Valerioageno avatar Sep 25 '22 12:09 Valerioageno

+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.

er1chu avatar Oct 03 '22 20:10 er1chu

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.

samtgarson avatar Oct 10 '22 13:10 samtgarson

We're planning to add types but not to convert the source to TypeScript for now.

clementroche avatar Oct 11 '22 16:10 clementroche

@clementroche is this PR a helpful start?

zachkrall avatar Oct 11 '22 18:10 zachkrall

This PR has been merged and pusblished in v0.2.11, can you check if everything is good for you ?

clementroche avatar Oct 12 '22 09:10 clementroche