Comment

Comment by runarberg

I have been using TypeScript in JS[1] mostly seamlessly. Types are annotated using doc comments above the thing your annotating.

It is a bit hard to define complex types. E.g. I couldn’t for the life of me annotate the return value of the pipe function:

    function pipe(init, ...ops) {
      return ops.reduce((acc, op) => op(acc), init)
    }
For these instances they suggest writing a declaration file[2]. However I have found the documentation isn’t really clear on this usecase (in fact I find the documentation of TypeScript somewhat lacking in general).

But overall getting these typehints into my editor environment has been worth it. And I haven’t had to sacrifice the save → run workflow.

1: https://www.typescriptlang.org/docs/handbook/type-checking-j...

2: https://www.typescriptlang.org/docs/handbook/declaration-fil...

EDIT: An example annotated JS file for typescript: https://github.com/runarberg/strawberry-router/blob/master/s...

`npm run check` just runs typescript’s type checker, there is no compile step.

parent runarberg 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton