Vinz243
Vinz243

Reputation: 9958

Importing typescript defintion into JSDoc

I'm trying to use ts-xor package that returns a typescript def :

export declare type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

Here is how I'm using it:

/**
 * @typedef {import('ts-xor')} XOR
 * @typedef {XOR<{
             ^^^
  *   small: true
  * }, {
  *   verySmall: true,
  * }>} ButtonProps
  * @typedef {React.FunctionComponent<ButtonProps>} ButtonComponent 
  */

I get :

 Type 'XOR' is not generic.ts(2315)

Edit TypeScript Playground Export (forked)

Upvotes: 1

Views: 114

Answers (1)

lepsch
lepsch

Reputation: 10389

Just declare the import of XOR with JSDoc @template like the following:

/**
 * @template T
 * @template U
 * @typedef {import('ts-xor').XOR<T,U>} XOR
 */

/**
 * @typedef {XOR<{
     small: true
   }, {
     verySmall: true,
   }>} ButtonProps
 * @typedef {React.FunctionComponent<ButtonProps>} ButtonComponent
 */

Upvotes: 1

Related Questions