DEV Community

Discussion on: Why so much hype over Typescript ?

 
brieucp profile image
brieucp • Edited

For the second example:

/**
 * @param { function(T): boolean} predicate
 * @returns { function(T[]): T[]}
 * @template T
 */
const filter = predicate => arr => arr.filter(predicate);
Enter fullscreen mode Exit fullscreen mode

For the third one:

/**
 * @typedef { Object } Foo
 * @property { 'Foo' } tag
 * @property { number } value
 */

 /**
 * @typedef { Object } Bar
 * @property { 'Bar' } tag
 * @property { number } value
 */

/**
 * 
 * @param {Foo|Bar} t
 * @returns {t is Foo}
 */
const isFoo = (t) => t.tag === 'Foo';
Enter fullscreen mode Exit fullscreen mode

Yes it's more verbose, I know
For the first one, my brain broke while trying to find a use case for it ^^. Types starting by an action verb are a strange concept.


I got your point, yes real typescript is certainly more powerfull that basic JSDoc but does everyone need it ? I'm pretty sure that most of the time I don't.

JSDoc does not fail at compile time if your types are incorrect.

It can, if you use typescript ^^.

My point is and have always been : You don't need to write typescript to have is benefits. The typescript parser/compiler understand JSDoc well enough. The overhead introduce by writing something else than pure javascript does not worth it (or so I think).

I don't understand why typescript is more than just a type checker. Yes I know you can use Babel and typescript together. But then when using non-typescript feature in .ts files, linters go crazy and unreliable.

I'm not saying that typescript is bad. It's just overengineered (and a little schizophrenic). If feel the same about using a full framework to implement a simple login page. You can but I'm missing the interest.

Thread Thread
 
brieucp profile image
brieucp • Edited

Ok so apparently t is Foo is not JSDoc compatible (if we need to use JSDoc cli). But vs code understand it right.
So you probably won this point too ;) but rewriting your function to avoid using type predicate is easy