Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.46 KB

export-your-types.md

File metadata and controls

36 lines (26 loc) · 1.46 KB

Item 67: Export All Types That Appear in Public APIs

Things to Remember

  • Export types that appear in any form in any public method. Your users will be able to extract them anyway, so you may as well make it easy for them.

Code Samples

interface SecretName {
  first: string;
  last: string;
}

interface SecretSanta {
  name: SecretName;
  gift: string;
}

export function getGift(name: SecretName, gift: string): SecretSanta {
  // ...
}

💻 playground


type MySanta = ReturnType<typeof getGift>;
//   ^? type MySanta = SecretSanta
type MyName = Parameters<typeof getGift>[0];
//   ^? type MyName = SecretName

💻 playground