Derive-Type: Generate TypeScript Definitions Automatically

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024
  • In this video I show the open-source package `derive-type` to automatically generate TypeScript type definitions based on invocations of JavaScript functions.
    Here's the GitHub repository:
    github.com/Dav...
    Contact:
    david.devonduty@gmail.com
    #javascript #typescript

ความคิดเห็น • 6

  • @everythingisfine9988
    @everythingisfine9988 2 ปีที่แล้ว +4

    Such a great project! Combining the speed/flexibility of "writing" JavaScript with the "type safety" of Typescript. I just got 2x questions. First, will this be supported in other file types that run JavaScript? ex: .jsx, .svelte or .html. Also, once the JSDoc "@type { import }" is generated are you planning to auto-remove "require('derive-type')(...arguments)" from the functions?
    Again, great work! 😀

    • @devonduty
      @devonduty  2 ปีที่แล้ว +2

      Thanks for this nice comment! In principle it should also work for other file types, as long as the function is called. Great suggestion about automatically removing the `require('derive-type')(...arguments)` call, I also thought about that but wasn't sure because it lets you rerun the type generation faster, but maybe I looked at it too much from a library-author point of view, usually it's enough to run it once. I'll think about removing it! Thanks again!

    • @devonduty
      @devonduty  2 ปีที่แล้ว +2

      Update: I've changed the behaviour, now the call to derive-type is automatically removed, thanks for this great suggestion!

    • @everythingisfine9988
      @everythingisfine9988 2 ปีที่แล้ว +1

      @@devonduty oh nice! I'll definitely give this a try. Maybe make a script to check every file in the src/* directory for the characters ''derive-type" and run the command at that path location 🤔 anyhow, excited to try this out, thanks again!

    • @devonduty
      @devonduty  2 ปีที่แล้ว +1

      @@everythingisfine9988 that's great! Keep in mind that you don't need to run the file which contains `derive-type`, just a file which eventually triggers the respective function execution, e.g. `npx derive-type npm test`.

    • @everythingisfine9988
      @everythingisfine9988 2 ปีที่แล้ว +2

      @@devonduty your really onto something. I just created a simple application and began creating just a couple basic components (a typical workflow on a job: not all companies have/require full test coverage). This would be an issue for encapsulated functions. So, I would just call the function below itself with the various properties giving them different data types attributes. Ex: myFunc(1, "name"). Then run the binary command in your docs. And it worked perfectly for a re-world application! Practically effortless type annotations with minimal file clutter 👍