Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 701 Bytes

methodnames.md

File metadata and controls

41 lines (30 loc) · 701 Bytes
description This utility type takes an Api interface as type argument and returns a union type of all the property names whose values are functions.

MethodNames

Example:

import type { MethodNames } from "tsafe";

type T = {
	x: number;
	y: number;
	method1(): void;
	method2(): void;
};

type TMethodNames = MethodNames<T>;

//resulting type is: "method1" | "method2"

The result will be the same if one or more of the methods are optional.

import type { MethodNames } from "tsafe";

type T = {
	x: number;
	y: number;
	method1(): void;
	method2?(): void;
};

type TMethodNames = MethodNames<T>;

//resulting type is: "method1" | "method2"