Skip to content

Commit

Permalink
Add InlineThisParameter utility type
Browse files Browse the repository at this point in the history
  • Loading branch information
emre1791 authored Feb 3, 2024
1 parent 9fc6549 commit e4c38c3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/typeUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type UnionToIntersection<T> = (T extends object ? (k: T) => void : never) extend
/** Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter. */
type ThisParameterType<T> = T extends (this: infer U, ...args: Array<any>) => any ? U : unknown;

/** Renames the `this` parameter to `self`, this allows passing compiler's noIndexWithoutCall diagnostic */
type InlineThisParameter<T> = T extends (...args: infer A) => infer R ? (self: any, ...args: A) => R : T;

/** Removes the 'this' parameter from a function type. */
type OmitThisParameter<T> = unknown extends ThisParameterType<T>
? T
Expand Down

0 comments on commit e4c38c3

Please sign in to comment.