2021-09-23

#dev

How to define unexported type which come from library

How to use cheerio.Root type in TypeScript

  • return type of a function: ReturnType
import cheerio, { load } from 'cheerio';

type CheerioRoot = ReturnType<typeof load>;
  • type of a parameter: Parameters
function foo(a: number, b: string) {
  // Do Something
}

type FooFirstParameterType = Parameters<typeof foo>[0]; // number
type FooSecondParameterType = Parameters<typeof foo>[1]; // string