I'm using the JSDoc form of TypeScript and am trying to use a generic that extends an object. My editor is giving me a TypeScript error for the index.js
code declaring the parameter of typeMyInterface<T>
, saying Type 'T' does not satisfy the constraint '{ a: number; }'.
How do I specify that I accept a generic parameter that constrains an object in JSDoc TypeScript?
// index.d.ts
declare interface MyInterface<T extends {a: number}> {
b: string;
}
// index.js
/**
* @template T
* @param {MyInterface<T>} impl
*/
function doStuff(impl) {
console.log(impl);
}
/**
* @template {{a: number}} T
* @param {MyInterface<T>} impl
*/
@template
constraints were implemented in pull request 24600
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With