On this page
ThisParameterType
Prev: `InstanceType` | Up: function_and_promise | Next: string_manipulation
Rel: function_and_promise, Conditional & Mapped Types
Ref: TypeScript Docs — Utility Types
Tags: #public #web #typescript #utility-types #function_and_promise #tier/specialized
Syntax & Overview
ThisParameterType<Fn> /* + OmitThisParameter<Fn> */
Extracts the explicit this parameter type from a function signature (or unknown if none).
Notes & Pitfalls
- Extracts the explicit
thisparameter type (orunknownif the function declares nothisparameter). Pair withOmitThisParameter<T>when binding.
Example
function toHex(this: number): string {
return this.toString(16);
}
type ThisVal = ThisParameterType<typeof toHex>; // number
const val: ThisVal = 255;
Linked from
Related notes
- tuts/typescript/utility_types/function_and_promise/InstanceType Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/function_and_promise Linked here; links to this page; shared tags: #typescript, #web
- tuts/typescript/type_system/conditional_and_mapped_types Linked here; shared tags: #typescript, #web
- tuts/typescript/utility_types/string_manipulation Linked here; shared tags: #typescript, #web
- tuts/typescript/builtins/any shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/as_const shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/enum shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/is shared tags: #tier, #typescript, #web