tomsma
tomsma

Reputation: 79

Why a function is a subset of an object in typescript?

type ccc = (() => 22) extends Record<string|symbol,any> ? true : false // true

I don't understand why it was designed this way

Upvotes: 1

Views: 63

Answers (1)

Connor Low
Connor Low

Reputation: 7186

Because a function is an object in JavaScript.

In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function objects.

Upvotes: 4

Related Questions