import { AnyFunction } from 'tsdef'; import { PickByValue } from 'utility-types'; /** * converts a non-arrow function type to an arrow function type. arrow functions are checked more strictly than * non-arrow functions * @see https://github.com/microsoft/TypeScript/pull/18654 * @example * declare class Foo { * notArrowFunction(value: T): void * isArrowFunction: (value: T) => void * } * type ArrowFunction = ToArrowFunction */ export type ToArrowFunction = { fn: (...args: Parameters) => ReturnType; }['fn']; /** * converts an arrow function type to a non-arrow function type. arrow functions are checked more strictly than * non-arrow functions * @see https://github.com/microsoft/TypeScript/pull/18654 * @example * declare class Foo { * notArrowFunction(value: T): void * isArrowFunction: (value: T) => void * } * type NotArrowFunction = ToNonArrowFunction */ export type ToNonArrowFunction = { fn(...args: Parameters): ReturnType; }['fn']; /** * transforms all methods in `T` into arrow functions, which makes typescript check it more strictly * @see https://github.com/microsoft/TypeScript/pull/18654 */ export type SafeVariance = { wrapped: T & { [Key in keyof T]: T[Key] extends AnyFunction ? ToArrowFunction : T[Key]; }; }['wrapped']; /** * transforms all methods in `T` into non-arrow functions, which turns off variance checks * * **WARNING:** doesn't work properly with private/protected methods * @see https://github.com/microsoft/TypeScript/pull/18654 */ export type UnsafeVariance = { wrapped: { [Key in keyof T]: T[Key] extends AnyFunction ? ToNonArrowFunction : T[Key]; }; }['wrapped']; /** * filters out properties of `T` that aren't a method of `T` (ie. its `this` type must be `T`) * @example * class A { * foo(value: number) {return 1} * bar = () => {} * baz(this: number) {} * qux = 1 * } * type B = Methods // { foo(value: number); bar: () => void; } */ export type Methods = PickByValue unknown>; //# sourceMappingURL=Function.d.ts.map