tsafe
GitHub
  • 👋What is tsafe?
  • ⚙️How to import
  • assert
  • Equals
  • id
  • is
  • objectKeys
  • exclude
  • isAmong
  • symToStr
  • ReturnType
  • Parameters
  • Param0
  • typeGuard
  • capitalize/uncapitalize
  • MethodNames
  • isPromiseLike
  • flip
  • objectEntries
  • objectFromEntries
  • UnionToIntersection
  • 🚧withDefaults
  • 📉UnpackPromise
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub

MethodNames

This utility type takes an Api interface as type argument and returns a union type of all the property names whose values are functions.

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"
Previouscapitalize/uncapitalizeNextisPromiseLike

Last updated 5 months ago

Was this helpful?