/**
* @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}
*/constisFoo=(t)=>t.tag==='Foo';
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.
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For the second example:
For the third one:
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.
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.
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