Example

 ~\newline
 ~\newline
  ~\newline
 ~\newline
 {\bfseries{A collection of essential Type\+Script types}} ~\newline
 \DoxyHorRuler{0}
  ~\newline
 ~\newline


\href{https://travis-ci.com/sindresorhus/type-fest}{\texttt{ }} \href{https://www.youtube.com/watch?v=9auOCbH5Ns4}{\texttt{ }}

Many of the types here should have been built-\/in. You can help by suggesting some of them to the \href{https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md}{\texttt{ Type\+Script project}}.

Either add this package as a dependency or copy-\/paste the needed types. No credit required. 👌

PR welcome for additional commonly needed types and docs improvements. Read the contributing guidelines first.\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31182}{}\doxysubsection{Install}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31182}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install type-\/fest }

\end{DoxyCode}


{\itshape Requires Type\+Script $>$=3.\+2}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31183}{}\doxysubsection{Usage}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31183}

\begin{DoxyCode}{0}
\DoxyCodeLine{import \{Except\} from 'type-\/fest';}
\DoxyCodeLine{}
\DoxyCodeLine{type Foo = \{}
\DoxyCodeLine{    unicorn: string;}
\DoxyCodeLine{    rainbow: boolean;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{type FooWithoutRainbow = Except<Foo, 'rainbow'>;}
\DoxyCodeLine{//=> \{unicorn: string\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31184}{}\doxysubsection{API}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31184}
Click the type names for complete docs.\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31185}{}\doxysubsubsection{Basic}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31185}

\begin{DoxyItemize}
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Primitive}}} -\/ Matches any \href{https://developer.mozilla.org/en-US/docs/Glossary/Primitive}{\texttt{ primitive value}}.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Class}}} -\/ Matches a \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes}{\texttt{ {\ttfamily class} constructor}}.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Typed\+Array}}} -\/ Matches any \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray}{\texttt{ typed array}}, like {\ttfamily Uint8\+Array} or {\ttfamily Float64\+Array}.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Json\+Object}}} -\/ Matches a JSON object.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Json\+Array}}} -\/ Matches a JSON array.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Json\+Value}}} -\/ Matches any valid JSON value.
\item \href{source/basic.d.ts}{\texttt{ {\ttfamily Observable\+Like}}} -\/ Matches a value that is like an \href{https://github.com/tc39/proposal-observable}{\texttt{ Observable}}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31186}{}\doxysubsubsection{Utilities}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31186}

\begin{DoxyItemize}
\item \href{source/except.d.ts}{\texttt{ {\ttfamily Except}}} -\/ Create a type from an object type without certain keys. This is a stricter version of \href{https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html\#the-omit-helper-type}{\texttt{ {\ttfamily Omit}}}.
\item \href{source/mutable.d.ts}{\texttt{ {\ttfamily Mutable}}} -\/ Convert an object with {\ttfamily readonly} keys into a mutable object. The inverse of {\ttfamily Readonly$<$T$>$}.
\item \href{source/merge.d.ts}{\texttt{ {\ttfamily Merge}}} -\/ Merge two types into a new type. Keys of the second type overrides keys of the first type.
\item \href{source/merge-exclusive.d.ts}{\texttt{ {\ttfamily Merge\+Exclusive}}} -\/ Create a type that has mutually exclusive keys.
\item \href{source/require-at-least-one.d.ts}{\texttt{ {\ttfamily Require\+At\+Least\+One}}} -\/ Create a type that requires at least one of the given keys.
\item \href{source/require-exactly-one.d.ts}{\texttt{ {\ttfamily Require\+Exactly\+One}}} -\/ Create a type that requires exactly a single key of the given keys and disallows more.
\item \href{source/partial-deep.d.ts}{\texttt{ {\ttfamily Partial\+Deep}}} -\/ Create a deeply optional version of another type. Use \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1401-L1406}{\texttt{ {\ttfamily Partial$<$T$>$}}} if you only need one level deep.
\item \href{source/readonly-deep.d.ts}{\texttt{ {\ttfamily Readonly\+Deep}}} -\/ Create a deeply immutable version of an {\ttfamily object}/{\ttfamily Map}/{\ttfamily Set}/{\ttfamily Array} type. Use \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1415-L1420}{\texttt{ {\ttfamily Readonly$<$T$>$}}} if you only need one level deep.
\item \href{source/literal-union.d.ts}{\texttt{ {\ttfamily Literal\+Union}}} -\/ Create a union type by combining primitive types and literal types without sacrificing auto-\/completion in IDEs for the literal type part of the union. Workaround for \href{https://github.com/Microsoft/TypeScript/issues/29729}{\texttt{ Microsoft/\+Type\+Script\#29729}}.
\item \href{source/promisable.d.ts}{\texttt{ {\ttfamily Promisable}}} -\/ Create a type that represents either the value or the value wrapped in {\ttfamily Promise\+Like}.
\item \href{source/opaque.d.ts}{\texttt{ {\ttfamily Opaque}}} -\/ Create an \href{https://codemix.com/opaque-types-in-javascript/}{\texttt{ opaque type}}.
\item \href{source/set-optional.d.ts}{\texttt{ {\ttfamily Set\+Optional}}} -\/ Create a type that makes the given keys optional.
\item \href{source/set-required.d.ts}{\texttt{ {\ttfamily Set\+Required}}} -\/ Create a type that makes the given keys required.
\item \href{source/promise-value.d.ts}{\texttt{ {\ttfamily Promise\+Value}}} -\/ Returns the type that is wrapped inside a {\ttfamily Promise}.
\item \href{source/async-return-type.d.ts}{\texttt{ {\ttfamily Async\+Return\+Type}}} -\/ Unwrap the return type of a function that returns a {\ttfamily Promise}.
\item \href{source/conditional-keys.d.ts}{\texttt{ {\ttfamily Conditional\+Keys}}} -\/ Extract keys from a shape where values extend the given {\ttfamily Condition} type.
\item \href{source/conditional-pick.d.ts}{\texttt{ {\ttfamily Conditional\+Pick}}} -\/ Like {\ttfamily Pick} except it selects properties from a shape where the values extend the given {\ttfamily Condition} type.
\item \href{source/conditional-except.d.ts}{\texttt{ {\ttfamily Conditional\+Except}}} -\/ Like {\ttfamily Omit} except it removes properties from a shape where the values extend the given {\ttfamily Condition} type.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31187}{}\doxysubsubsection{Miscellaneous}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31187}

\begin{DoxyItemize}
\item \href{source/package-json.d.ts}{\texttt{ {\ttfamily Package\+Json}}} -\/ Type for \href{https://docs.npmjs.com/creating-a-package-json-file}{\texttt{ npm\textquotesingle{}s {\ttfamily package.\+json} file}}.
\item \href{source/tsconfig-json.d.ts}{\texttt{ {\ttfamily Ts\+Config\+Json}}} -\/ Type for \href{https://www.typescriptlang.org/docs/handbook/tsconfig-json.html}{\texttt{ Type\+Script\textquotesingle{}s {\ttfamily tsconfig.\+json} file}} (Type\+Script 3.\+7).
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31188}{}\doxysubsection{Declined types}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31188}
{\itshape If we decline a type addition, we will make sure to document the better solution here.}


\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/type-fest/pull/7}{\texttt{ {\ttfamily Diff} and {\ttfamily Spread}}} -\/ The PR author didn\textquotesingle{}t provide any real-\/world use-\/cases and the PR went stale. If you think this type is useful, provide some real-\/world use-\/cases and we might reconsider.
\item \href{https://github.com/sindresorhus/type-fest/issues/33}{\texttt{ {\ttfamily Dictionary}}} -\/ You only save a few characters ({\ttfamily Dictionary$<$number$>$} vs {\ttfamily Record$<$string, number$>$}) from \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1429-L1434}{\texttt{ {\ttfamily Record}}}, which is more flexible and well-\/known. Also, you shouldn\textquotesingle{}t use an object as a dictionary. We have {\ttfamily Map} in Java\+Script now.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31189}{}\doxysubsection{Tips}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31189}
\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31190}{}\doxysubsubsection{Built-\/in types}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31190}
There are many advanced types most users don\textquotesingle{}t know about.


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1401-L1406}{\texttt{ {\ttfamily Partial$<$T$>$}}} -\/ Make all properties in {\ttfamily T} optional. $<$details$>$
\end{DoxyItemize}

\href{https://www.typescriptlang.org/play/\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts interface Node\+Config \{ app\+Name\+: string; port\+: number; \}

class Node\+App\+Builder \{ private configuration\+: Node\+Config = \{ app\+Name\+: \textquotesingle{}Node\+App\textquotesingle{}, port\+: 3000 \};

private update\+Config$<$\+Key extends keyof Node\+Config$>$(key\+: Key, value\+: Node\+Config\mbox{[}\+Key\mbox{]}) \{ this.\+configuration\mbox{[}key\mbox{]} = value; \}

config(config\+: Partial$<$\+Node\+Config$>$) \{ type Node\+Config\+Key = keyof Node\+Config;

for (const key of Object.\+keys(config) as Node\+Config\+Key\mbox{[}\mbox{]}) \{ const update\+Value = config\mbox{[}key\mbox{]};

if (update\+Value === undefined) \{ continue; \}

this.\+update\+Config(key, update\+Value); \}

return this; \} \}

// {\ttfamily Partial$<$Node\+Config$>$}\`{} allows us to provide only a part of the // Node\+Config interface. new Node\+App\+Builder().config(\{app\+Name\+: \textquotesingle{}To\+Do\+App\textquotesingle{}\}); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1408-L1413}{\texttt{ {\ttfamily Required$<$T$>$}}} -\/ Make all properties in {\ttfamily T} required. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\#code/AQ4SwOwFwUwJwGYEMDGNgGED21VQGJZwC2wA3gFCjXAzFJgA2A-AFzADOUckA5gNxUaIYjA4ckvGG07c+g6gF8KQkAgCuEFFDA5O6gEbEwUbLm2ESwABQIixACJIoSdgCUYAR3Vg4MACYAPGYuFvYAfACU5Ko0APRxwADKMBD+wFAAFuh2Vv7OSBlYGdmc8ABu8LHKsRyGxqY4oQT21pTCIHQMjOwA5DAAHgACxAAOjDAAdChYxL0ANLHUouKSMH0AEmAAhJhY6ozpAJ77GTCMjMCiV0ToSAb7UJPPC9WRgrEJwAAqR6MwSRQPFGUFocDgRHYxnEfGAowh-zgUCOwF6KwkUl6tXqJhCeEsxDaS1AXSYfUGI3GUxmc0WSneQA}{\texttt{ Playground}}

\`{}\`{}\`{}ts interface Contact\+Form \{ email?\+: string; message?\+: string; \}

function submit\+Contact\+Form(form\+Data\+: Required$<$\+Contact\+Form$>$) \{ // Send the form data to the server. \}

submit\+Contact\+Form(\{ email\+: \textquotesingle{}\href{mailto:ex@mple.com}{\texttt{ ex@mple.\+com}}\textquotesingle{}, message\+: \textquotesingle{}Hi! Could you tell me more about…\textquotesingle{}, \});

// Type\+Script error\+: missing property \textquotesingle{}message\textquotesingle{} submit\+Contact\+Form(\{ email\+: \textquotesingle{}\href{mailto:ex@mple.com}{\texttt{ ex@mple.\+com}}\textquotesingle{}, \}); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1415-L1420}{\texttt{ {\ttfamily Readonly$<$T$>$}}} -\/ Make all properties in {\ttfamily T} readonly. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts enum Log\+Level \{ Off, Debug, Error, Fatal \};

interface Logger\+Config \{ name\+: string; level\+: Log\+Level; \}

class Logger \{ config\+: Readonly$<$\+Logger\+Config$>$;

constructor(\{name, level\}\+: Logger\+Config) \{ this.\+config = \{name, level\}; Object.\+freeze(this.\+config); \} \}

const config\+: Logger\+Config = \{ name\+: \textquotesingle{}My\+App\textquotesingle{}, level\+: Log\+Level.\+Debug \};

const logger = new Logger(config);

// Type\+Script Error\+: cannot assign to read-\/only property. logger.\+config.\+level = Log\+Level.\+Error;

// We are able to edit config variable as we please. config.\+level = Log\+Level.\+Error; \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1422-L1427}{\texttt{ {\ttfamily Pick$<$T, K$>$}}} -\/ From {\ttfamily T}, pick a set of properties whose keys are in the union {\ttfamily K}. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts interface Article \{ title\+: string; thumbnail\+: string; content\+: string; \}

// Creates new type out of the {\ttfamily Article} interface composed // from the Articles\textquotesingle{} two properties\+: {\ttfamily title} and {\ttfamily thumbnail}. // {\ttfamily Article\+Preview = \{title\+: string; thumbnail\+: string\}} type Article\+Preview = Pick$<$Article, \textquotesingle{}title\textquotesingle{} $\vert$ \textquotesingle{}thumbnail\textquotesingle{}$>$;

// Render a list of articles using only title and description. function render\+Article\+Previews(previews\+: Article\+Preview\mbox{[}$\,$\mbox{]})\+: HTMLElement \{ const articles = document.\+create\+Element(\textquotesingle{}div\textquotesingle{});

for (const preview of previews) \{ // Append preview to the articles. \}

return articles; \}

const articles = render\+Article\+Previews(\mbox{[} \{ title\+: \textquotesingle{}Type\+Script tutorial!\textquotesingle{}, thumbnail\+: \textquotesingle{}/assets/ts.jpg\textquotesingle{} \} \mbox{]}); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1429-L1434}{\texttt{ {\ttfamily Record$<$K, T$>$}}} -\/ Construct a type with a set of properties {\ttfamily K} of type {\ttfamily T}. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts // Positions of employees in our company. type Member\+Position = \textquotesingle{}intern\textquotesingle{} $\vert$ \textquotesingle{}developer\textquotesingle{} $\vert$ \textquotesingle{}tech-\/lead\textquotesingle{};

// Interface describing properties of a single employee. interface Employee \{ first\+Name\+: string; last\+Name\+: string; years\+Of\+Experience\+: number; \}

// Create an object that has all possible {\ttfamily Member\+Position} values set as keys. // Those keys will store a collection of Employees of the same position. const team\+: Record$<$\+Member\+Position, Employee\mbox{[}$\,$\mbox{]}$>$ = \{ intern\+: \mbox{[}\mbox{]}, developer\+: \mbox{[}\mbox{]}, \textquotesingle{}tech-\/lead\textquotesingle{}\+: \mbox{[}\mbox{]}, \};

// Our team has decided to help John with his dream of becoming Software Developer. team.\+intern.\+push(\{ first\+Name\+: \textquotesingle{}John\textquotesingle{}, last\+Name\+: \textquotesingle{}Doe\textquotesingle{}, years\+Of\+Experience\+: 0 \});

// {\ttfamily Record} forces you to initialize all of the property keys. // Type\+Script Error\+: \char`\"{}tech-\/lead\char`\"{} property is missing const team\+Empty\+: Record$<$\+Member\+Position, null$>$ = \{ intern\+: null, developer\+: null, \}; \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1436-L1439}{\texttt{ {\ttfamily Exclude$<$T, U$>$}}} -\/ Exclude from {\ttfamily T} those types that are assignable to {\ttfamily U}. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts interface Server\+Config \{ port\+: null $\vert$ string $\vert$ number; \}

type Request\+Handler = (request\+: Request, response\+: Response) =$>$ void;

// Exclude {\ttfamily null} type from {\ttfamily null $\vert$ string $\vert$ number}. // In case the port is equal to {\ttfamily null}, we will use default value. function get\+Port\+Value(port\+: Exclude$<$Server\+Config\mbox{[}\textquotesingle{}port\textquotesingle{}\mbox{]}, null$>$)\+: number \{ if (typeof port === \textquotesingle{}string\textquotesingle{}) \{ return parse\+Int(port, 10); \}

return port; \}

function start\+Server(handler\+: Request\+Handler, config\+: Server\+Config)\+: void \{ const server = require(\textquotesingle{}http\textquotesingle{}).create\+Server(handler);

const port = config.\+port === null ? 3000 \+: get\+Port\+Value(config.\+port); server.\+listen(port); \} \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1441-L1444}{\texttt{ {\ttfamily Extract$<$T, U$>$}}} -\/ Extract from {\ttfamily T} those types that are assignable to {\ttfamily U}. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts declare function unique\+Id()\+: number;

const ID = Symbol(\textquotesingle{}ID\textquotesingle{});

interface Person \{

name\+: string; age\+: number; \}

// Allows changing the person data as long as the property key is of string type. function change\+Person\+Data$<$ Obj extends Person, Key extends Extract$<$keyof Person, string$>$, Value extends Obj\mbox{[}Key\mbox{]} $>$ (obj\+: Obj, key\+: Key, value\+: Value)\+: void \{ obj\mbox{[}key\mbox{]} = value; \}

// Tiny Andrew was born. const andrew = \{

name\+: \textquotesingle{}Andrew\textquotesingle{}, age\+: 0, \};

// Cool, we\textquotesingle{}re fine with that. change\+Person\+Data(andrew, \textquotesingle{}name\textquotesingle{}, \textquotesingle{}Pony\textquotesingle{});

// Goverment didn\textquotesingle{}t like the fact that you wanted to change your identity. change\+Person\+Data(andrew, ID, unique\+Id()); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1446-L1449}{\texttt{ {\ttfamily Non\+Nullable$<$T$>$}}} -\/ Exclude {\ttfamily null} and {\ttfamily undefined} from {\ttfamily T}. $<$details$>$
\end{DoxyItemize}

Example

Works with 
\begin{DoxyCode}{0}
\DoxyCodeLine{strictNullChecks}

\end{DoxyCode}
 set to 
\begin{DoxyCode}{0}
\DoxyCodeLine{true}

\end{DoxyCode}
. (Read more \href{https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html}{\texttt{ here}})

\href{https://typescript-play.js.org/?target=6\#code/C4TwDgpgBACg9gJ2AOQK4FsBGEFQLxQDOwCAlgHYDmUAPlORtrnQwDasDcAUFwPQBU-WAEMkUOADMowqAGNWwwoSgATCBIqlgpOOSjAAFsOBRSy1IQgr9cKJlSlW1mZYQA3HFH68u8xcoBlHA8EACEHJ08Aby4oKDBUTFZSWXjEFEYcAEIALihkXTR2YSSIAB54JDQsHAA+blj4xOTUsHSACkMzPKD3HHDHNQQAGjSkPMqMmoQASh7g-oihqBi4uNIpdraxPAI2VhmVxrX9AzMAOm2ppnwoAA4ABifuE4BfKAhWSyOTuK7CS7pao3AhXF5rV48E4ICDAVAIPT-cGQyG+XTEIgLMJLTx7CAAdygvRCA0iCHaMwarhJOIQjUBSHaACJHk8mYdeLwxtdcVAAOSsh58+lXdr7Dlcq7A3n3J4PEUdADMcspUE53OluAIUGVTx46oAKuAIAFZGQwCYAKIIBCILjUxaDHAMnla+iodjcIA}{\texttt{ Playground}}

\`{}\`{}\`{}ts type Port\+Number = string $\vert$ number $\vert$ null;

/$\ast$$\ast$ Part of a class definition that is used to build a server $\ast$/ class Server\+Builder \{ port\+Number!\+: Non\+Nullable$<$\+Port\+Number$>$;

port(this\+: Server\+Builder, port\+: Port\+Number)\+: Server\+Builder \{ if (port == null) \{ this.\+port\+Number = 8000; \} else \{ this.\+port\+Number = port; \}

return this; \} \}

const server\+Builder = new Server\+Builder();

server\+Builder .port(\textquotesingle{}8000\textquotesingle{}) // port\+Number = \textquotesingle{}8000\textquotesingle{} .port(null) // port\+Number = 8000 .port(3000); // port\+Number = 3000

// Type\+Script error server\+Builder.\+port\+Number = null; \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1451-L1454}{\texttt{ {\ttfamily Parameters$<$T$>$}}} -\/ Obtain the parameters of a function type in a tuple. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\#code/GYVwdgxgLglg9mABAZwBYmMANgUwBQxgAOIUAXIgIZgCeA2gLoCUFAbnDACaIDeAUIkQB6IYgCypSlBxUATrMo1ECsJzgBbLEoipqAc0J7EMKMgDkiHLnU4wp46pwAPHMgB0fAL58+oSLARECEosLAA5ABUYG2QAHgAxJGdpVWREPDdMylk9ZApqemZEAF4APipacrw-CApEgBogkKwAYThwckQwEHUAIxxZJl4BYVEImiIZKF0oZRwiWVdbeygJmThgOYgcGFYcbhqApCJsyhtpWXcR1cnEePBoeDAABVPzgbTixFeFd8uEsClADcIxGiygIFkSEOT3SmTc2VydQeRx+ZxwF2QQ34gkEwDgsnSuFmMBKiAADEDjIhYk1Qm0OlSYABqZnYka4xA1DJZHJYkGc7yCbyeRA+CAIZCzNAYbA4CIAdxg2zJwVCkWirjwMswuEaACYmCCgA}{\texttt{ Playground}}

\`{}\`{}\`{}ts function shuffle(input\+: any\mbox{[}$\,$\mbox{]})\+: void \{ // Mutate array randomly changing its\textquotesingle{} elements indexes. \}

function call\+NTimes$<$Fn extends (...args\+: any\mbox{[}\mbox{]}) =$>$ any$>$ (func\+: Fn, call\+Count\+: number) \{ // Type that represents the type of the received function parameters. type Function\+Parameters = Parameters$<$\+Fn$>$;

return function (...args\+: Function\+Parameters) \{ for (let i = 0; i $<$ call\+Count; i++) \{ func(...\+args); \} \} \}

const shuffle\+Twice = call\+NTimes(shuffle, 2); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1456-L1459}{\texttt{ {\ttfamily Constructor\+Parameters$<$T$>$}}} -\/ Obtain the parameters of a constructor function type in a tuple. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts class Article\+Model \{ title\+: string; content?\+: string;

constructor(title\+: string) \{ this.\+title = title; \} \}

class Instance\+Cache$<$T extends (new (...args\+: any\mbox{[}\mbox{]}) =$>$ any)$>$ \{ private Class\+Constructor\+: T; private cache\+: Map$<$string, Instance\+Type$<$\+T$>$$>$ = new Map();

constructor (ctr\+: T) \{ this.\+Class\+Constructor = ctr; \}

get\+Instance (...args\+: Constructor\+Parameters$<$\+T$>$)\+: Instance\+Type$<$\+T$>$ \{ const hash = this.\+calculate\+Arguments\+Hash(...\+args);

const existing\+Instance = this.\+cache.\+get(hash); if (existing\+Instance !== undefined) \{ return existing\+Instance; \}

return new this.\+Class\+Constructor(...\+args); \}

private calculate\+Arguments\+Hash(...\+args\+: any\mbox{[}$\,$\mbox{]})\+: string \{ // Calculate hash. return \textquotesingle{}hash\textquotesingle{}; \} \}

const article\+Cache = new Instance\+Cache(\+Article\+Model); const amazon\+Article = article\+Cache.\+get\+Instance(\textquotesingle{}Amazon forests burining!\textquotesingle{}); \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1461-L1464}{\texttt{ {\ttfamily Return\+Type$<$T$>$}}} – Obtain the return type of a function type. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}{\ttfamily ts /$\ast$$\ast$ Provides every element of the iterable}iter{\ttfamily into the}callback\`{} function and stores the results in an array. $\ast$/ function map\+Iter$<$ Elem, Func extends (elem\+: Elem) =$>$ any, Ret extends Return\+Type$<$\+Func$>$ $>$(iter\+: Iterable$<$\+Elem$>$, callback\+: Func)\+: Ret\mbox{[}\mbox{]} \{ const mapped\+: Ret\mbox{[}\mbox{]} = \mbox{[}\mbox{]};

for (const elem of iter) \{ mapped.\+push(callback(elem)); \}

return mapped; \}

const set\+Object\+: Set$<$string$>$ = new Set(); const map\+Object\+: Map$<$number, string$>$ = new Map();

map\+Iter(set\+Object, (value\+: string) =$>$ value.\+index\+Of(\textquotesingle{}Foo\textquotesingle{})); // number\mbox{[}\mbox{]}

map\+Iter(map\+Object, (\mbox{[}key, value\mbox{]}\+: \mbox{[}number, string\mbox{]}) =$>$ \{ return key \% 2 === 0 ? value \+: \textquotesingle{}Odd\textquotesingle{}; \}); // string\mbox{[}\mbox{]} \`{}\`{}\`{} $<$/details$>$


\begin{DoxyItemize}
\item \href{https://github.com/Microsoft/TypeScript/blob/2961bc3fc0ea1117d4e53bc8e97fa76119bc33e3/src/lib/es5.d.ts\#L1466-L1469}{\texttt{ {\ttfamily Instance\+Type$<$T$>$}}} – Obtain the instance type of a constructor function type. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts class Idle\+Service \{ do\+Nothing ()\+: void \{\} \}

class News \{ title\+: string; content\+: string;

constructor(title\+: string, content\+: string) \{ this.\+title = title; this.\+content = content; \} \}

const instance\+Counter\+: Map$<$\+Function, number$>$ = new Map();

interface Constructor \{ new(...\+args\+: any\mbox{[}$\,$\mbox{]})\+: any; \}

// Keep track how many instances of {\ttfamily Constr} constructor have been created. function get\+Instance$<$ Constr extends Constructor, Args extends Constructor\+Parameters$<$\+Constr$>$ $>$(constructor\+: Constr, ...args\+: Args)\+: Instance\+Type$<$\+Constr$>$ \{ let count = instance\+Counter.\+get(constructor) $\vert$$\vert$ 0;

const instance = new constructor(...\+args);

instance\+Counter.\+set(constructor, count + 1);

console.\+log({\ttfamily Created \$\{count + 1\} instances of \$\{Constr.\+name\} class});

return instance; \}

\begin{DoxyVerb}const idleService = getInstance(IdleService);
// Will log: `Created 1 instances of IdleService class`
const newsEntry = getInstance(News, 'New ECMAScript proposals!', 'Last month...');
// Will log: `Created 1 instances of News class`
```
</details>
\end{DoxyVerb}

\begin{DoxyItemize}
\item \href{https://github.com/microsoft/TypeScript/blob/71af02f7459dc812e85ac31365bfe23daf14b4e4/src/lib/es5.d.ts\#L1446}{\texttt{ {\ttfamily Omit$<$T, K$>$}}} – Constructs a type by picking all properties from T and then removing K. $<$details$>$
\end{DoxyItemize}

Example

\href{https://typescript-play.js.org/?target=6\# }{\texttt{ Playground}}

\`{}\`{}\`{}ts interface Animal \{ image\+Url\+: string; species\+: string; images\+: string\mbox{[}\mbox{]}; paragraphs\+: string\mbox{[}\mbox{]}; \}

// Creates new type with all properties of the {\ttfamily Animal} interface // except \textquotesingle{}images\textquotesingle{} and \textquotesingle{}paragraphs\textquotesingle{} properties. We can use this // type to render small hover tooltip for a wiki entry list. type Animal\+Short\+Info = Omit$<$Animal, \textquotesingle{}images\textquotesingle{} $\vert$ \textquotesingle{}paragraphs\textquotesingle{}$>$;

function render\+Animal\+Hover\+Info (animals\+: Animal\+Short\+Info\mbox{[}\mbox{]})\+: HTMLElement \{ const container = document.\+create\+Element(\textquotesingle{}div\textquotesingle{}); // Internal implementation. return container; \} \`{}\`{}\`{} $<$/details$>$

You can find some examples in the \href{https://www.typescriptlang.org/docs/handbook/advanced-types.html\#predefined-conditional-types}{\texttt{ Type\+Script docs}}.\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31191}{}\doxysubsection{Maintainers}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31191}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus}{\texttt{ Sindre Sorhus}}
\item \href{https://github.com/CvX}{\texttt{ Jarek Radosz}}
\item \href{https://github.com/BendingBender}{\texttt{ Dimitri Benin}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_type_fest_readme_autotoc_md31192}{}\doxysubsection{License}\label{md_sfcode_node_modules_type_fest_readme_autotoc_md31192}
(MIT OR CC0-\/1.\+0)

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-type-fest?utm_source=npm-type-fest&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for this package with a Tidelift subscription}} }} ~\newline
 \textsubscript{ Tidelift helps make open source sustainable for maintainers while giving companies~\newline
assurances about security, maintenance, and licensing for their dependencies. }  