Importing typescript defintion into JSDoc

Viewed 21

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)

1 Answers

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
 */
Related