# Typescript - Tips & Tricks - Advanced Types > Hi Guys, Today I'll show you some advanced utilities exposed by the typescript language. Let's... - **Author**: Luca Del Puppo (@puppo92) — AI Native Engineer at Nearform - **Published**: Mar 31, 2021 - **Canonical URL**: https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-advanced-types/ - **Series**: TypeScript - Tips & Tricks (Part 20 of 21) — https://delpuppo.net/blog/series/ts-tips-and-tricks/ - **Series LLMs.txt**: https://delpuppo.net/blog/series/ts-tips-and-tricks/llms.txt - **Category**: TypeScript - **Tags**: typescript, webdev - **Hashnode Mirror**: https://blog.delpuppo.net/typescript-tips-tricks-advanced-types - **Dev.to Mirror**: https://dev.to/playfulprogramming/typescript-tips-tricks-advanced-types-3pp8 - **Blog Index LLMs.txt**: https://delpuppo.net/blog/llms.txt ## Series Context: TypeScript - Tips & Tricks - Part 1: [Typescript - Tips & Tricks - typeof](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-typeof/) - Part 2: [Typescript - Tips & Tricks - Literal Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-literal-types/) - Part 3: [Typescript - Tips & Tricks - keyof](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-keyof/) - Part 4: [Typescript - Tips & Tricks - Union and Intersection](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-union-and-intersection/) - Part 5: [Typescript - Tips & Tricks - Overloaded Functions](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-overloaded-functions/) - Part 6: [Typescript - Tips & Tricks - this parameter](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-this-parameter/) - Part 7: [Typescript - Tips & Tricks - any vs. unknown](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-any-vs-unknown/) - Part 8: [Typescript - Tips & Tricks - Optional modifier](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-optional-modifier/) - Part 9: [Typescript - Tips & Tricks - Index Signature](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-index-signature/) - Part 10: [Typescript - Tips & Tricks - readonly modifier](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-readonly-modifier/) - Part 11: [Typescript - Tips & Tricks - Readonly Array](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-readonly-array/) - Part 12: [Typescript - Tips & Tricks - Tuple](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-tuple/) - Part 13: [Typescript - Tips & Tricks - Non-null assertion operator](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-non-null-assertion-operator/) - Part 14: [Typescript - Tips & Tricks - Never type](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-never-type/) - Part 15: [Typescript - Tips & Tricks - Assert Function](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-assert-function/) - Part 16: [Typescript - Tips & Tricks - Type Guard](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-type-guard/) - Part 17: [Typescript - Tips & Tricks - Conditional Type](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-conditional-type/) - Part 18: [Typescript - Tips & Tricks - infer keyword](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-infer-keyword/) - Part 19: [Typescript - Tips & Tricks - Mapped Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-mapped-types/) - Part 20: [Typescript - Tips & Tricks - Advanced Types](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-advanced-types/) **(Current Article)** - Part 21: [Typescript - Tips & Tricks - Rest Parameters & Rest Arguments](https://delpuppo.net/blog/ts-tips-and-tricks/typescript-tips-tricks-rest-parameters-rest-arguments/) --- Hi Guys, Today I'll show you some advanced utilities exposed by the typescript language. Let's start! ## Utilities for Types * [Partial](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) This utility allows you to add the optional modifier to all the properties of your type. ```ts type PartialPoint = Partial<{ x: number; y: number }>; // { x?: number | undefined; y?: number | undefined; } ``` * [Required](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) This utility allows you to remove the optional modifier to all the properties of your type. ```ts type RequiredPoint = Required<{ x?: number; y?: number }>; // { x: number; y: number; } ``` * [ReadOnly](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) This utility allows you to add the read-only modifier to all the properties of your type. ```ts type ReadOnlyPoint = ReadOnly<{ x: number; y: number }>; // { readonly x: number; readonly y: number; } ``` * [Pick](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys) This utility allows you to get a subset of properties from another type. ```ts type PickPoint = Pick<{ x: number; y: number }, "x">; // { x: number; } ``` * [Omit](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys) This utility allows you to exclude some properties from another type. ```ts type OmitPoint = Omit<{ x: number; y: number }, "x">; // { y: number; } ``` * [Record](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeystype) This utility allows you to map the properties of a type to another type. ```ts type Point = { x: number; y: number; }; type PointRecord = Record; // { x: number | null; y: number | null; } ``` * [Exclude](https://www.typescriptlang.org/docs/handbook/utility-types.html#excludetype-excludedunion) This utility allows you to remove some types from a [union type](https://dev.to/puppo/typescript-tips-tricks-union-and-intersection-1a9l). ```ts type ExcludeType = Exclude<"x" | "y", "x">; // "y" ``` * [Extract](https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttype-union) This utility allows you to get some types from a [union type](https://dev.to/puppo/typescript-tips-tricks-union-and-intersection-1a9l). ```ts type ExtractType = Extract<"x" | "y", "x">; // "x" ``` * [NonNullable](https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype) This utility allows you to remove the _undefined_ and _null_ types from a [union type](https://dev.to/puppo/typescript-tips-tricks-union-and-intersection-1a9l). ```ts type NonNullableType = NonNullable; // string | number ``` ## Utilities for Function and Class * [Parameters](https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype) This utility allows you to extract from a function its parameters. ```ts function createPoint(x: number, y: number) { return { x, y }; } type ParametersType = Parameters; // [x: number, y: number] ``` * [ConstructorParameters](https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype) This utility allows you to extract from a class its constructor parameters. ```ts class Point { constructor(x: number, y: number) {} } type ConstructorParametersType = ConstructorParameters; // [x: number, y: number] ``` * [ReturnType](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) This utility allows you to get the return type from a function. ```ts function createPoint(x: number, y: number) { return { x, y }; } type CreatePointReturnType = ReturnType; // { x: number; y: number; } ``` * [InstanceType](https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype) This utility allows you to construct a type consisting of the instance type of a construction function type. ```ts class Point { constructor(x: number, y: number) {} } type InstanceTypePoint = InstanceType; // Point type InstanceTypeString = InstanceType; // Error: Type 'string' does not satisfy the constraint 'new (...args: any) => any' ``` * [ThisParameterType](https://www.typescriptlang.org/docs/handbook/utility-types.html#thisparametertypetype) This utility allows you to extract the [this parameter](https://dev.to/puppo/typescript-tips-tricks-this-parameter-7n6) from a function type, or unknown if the function type has no this parameter. ```ts function toHex(this: Number) { return this.toString(16); } function numberToString(n: ThisParameterType) { return toHex.apply(n); } numberToString(12) ``` * [OmitThisParameter](https://www.typescriptlang.org/docs/handbook/utility-types.html#omitthisparametertype) This utility allows you to remove the [this parameter](https://dev.to/puppo/typescript-tips-tricks-this-parameter-7n6) from a function type. ```ts function toHex(this: Number) { return this.toString(16); } const fiveToHex: OmitThisParameter = toHex.bind(5); fiveToHex() ``` ## Utilities to Manipulation String Types * Uppercase This utility allows converting your types to uppercase format. ```ts type StringUppercase = Uppercase<"getX" | "getY" | "setX" | "setY">; // "GETX" | "GETY" | "SETX" | "SETY" ``` * Lowercase This utility allows you to convert your types to lowercase format. ```ts type StringLowercase = Lowercase<"getX" | "getY" | "setX" | "setY">; // "getx" | "gety" | "setx" | "sety" ``` * Capitalize This utility allows you to convert your types to capitalize format. ```ts type StringCapitalize = Capitalize<"getX" | "getY" | "setX" | "setY">; // "GetX" | "GetY" | "SetX" | "SetY" ``` * Uncapitalize This utility allows you to convert your types to uncapitalize format. ```ts type StringUncapitalize = Uncapitalize<"GetX" | "GetY" | "SetX" | "SetY">; // "getX" | "getY" | "setX" | "setY" ``` I hope these utilities will help you in the future. That's all for today. See you soon Guys!