8

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);
}

1 Answer 1

10
/**
 * @template {{a: number}} T
 * @param {MyInterface<T>} impl
 */

@template constraints were implemented in pull request 24600

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.