5

I want to add some type information to a legacy JavaScript project. I added a d.ts-File and declared some types and some exports. The JavaScript file exports a instance and class. Like this:

const { Foo } = require('foo');

const stuff = {foo: new Foo(), FooClass: Foo};
module.exports = stuff;

This is my d.ts-file:

import { Foo } from 'foo';

export const foo: Foo;
//???How to declare the export of FooClass???

The best I got so far is export class FooClass extends Foo{}, but I would prefer not to introduce this virtual inheritence.

1 Answer 1

3

The type of the constructor of a class (FooClass) is typeof ClassName (typeof Foo), so:

import { Foo } from 'foo';

export const foo: Foo;
export const FooClass: typeof Foo;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.