#How to get a constructor from a class?

8 messages · Page 1 of 1 (latest)

sour harbor
#

For example, see the following small playground code snippet that illustrates the issue:

[see below]

viral jasperBOT
#
Zamiel#8743

Preview:```ts
/**

  • A utility type to get the constructor of the corresponding class.
    */
    type Constructor<T> = "what do I put here?"

class Foo {
someValue = 123
}

type FooConstructor = Constructor<Foo>```

broken oak
#

From the class instance, not generally possible unless you add a property to the class that can be used to reference it... TS doesn't type Foo.constructor as typeof Foo

sour harbor
#

Oh, but it looks like I can explicitly use typeof, which is all I need for now, thanks.

#

!close

#

How do I close with the new format?

broken oak
#

Three dots at the top right -> Close Post, or just let it fall to the bottom

#

There's some discussion about bringing close back in #meta-discussion