Skip to main content
Module

x/drash/src/core/Types.ts>MethodOf

A microframework for building JavaScript HTTP applications. Runtime-agnostic. Strongly typed.
Latest
type alias MethodOf
import { type MethodOf } from "https://deno.land/x/drash@v3.0.0-beta.2/src/core/Types.ts";

A utility type that lets the compiler and reader know: the member assigned this type is a method of the given generic Object.

Examples

Example 1

class One {
  a() {}
  b() {}
  c() {}
}

const methods = ["a", "b", "c"];

const one = new One();

one[methods[0]]();
// Element implicitly has an 'any' type because expression of type 'string'
// can't be used to index type 'One'.(7053)

one[methods[0] as MethodOf<One>]();
// OK
definition: [K in keyof Object]: Object[K] extends Func ? K : never[keyof Object]