/**
* @typedef Animal
* @property {string} noise
*/
/**
* @typedef Duck
* @property {string} noise
* @property {number} wings
*/
/**
* @param {Animal} a
*/
function TestAnimal(a) { console.log(a.noise) }
// 0. warning
TestAnimal({ noise: 'quack', wings: 2 }) // Object literal may only specify known properties, and 'wings' does not exist in type 'Animal'.ts(2353)
// 1. multiple
const bear = { noise: 'roar', feet: 4 }
TestAnimal(bear)
// 2. single, extra parentheses
TestAnimal(/** @type {Animal} */({ noise: 'meow', tails: 1 }))
Are these the only 2 ways to type assert without warning in VSCode? I find both unwieldy and something closer to (0) would be much preferred.
Another solution I’ve come across is
/**
* @typedef {{
* noise: string
* [others: string]: any
* }} Animal
*/
but it’s less than ideal since I have to apply it to all typedef
I might extend from and defeats its purpose in some cases
I dont want to use
/** @typedef {Duck | Bear | Cat} Animal */
either, since this requires Animal
to keep track of everything that extends it and doesn’t allow other users to extend it