Skip to content

guards.Function.isCtor

github-actions[bot] edited this page Jun 8, 2026 · 1 revision

@zenstone/ts-utils / guards / isCtor

Function: isCtor()

isCtor<T>(val): val is Constructor<T>

Defined in: src/guards/index.ts:306

检查值是否为可 new 调用的构造函数(class 或普通函数)

箭头函数没有 prototype,返回 false;class 和普通函数返回 true

Type Parameters

T

T = object

Parameters

val

unknown

任意值

Returns

val is Constructor<T>

Example

isCtor(class Foo {})        // true  → val is Constructor<object>
isCtor<Foo>(class Foo {})   // true  → val is Constructor<Foo>
isCtor(() => {})             // false
isCtor(null)                 // false

Clone this wiki locally