简体   繁体   中英

How can I return a new Type in typescript?

I'm trying to write a d.ts file for a lib which provide a static method extend to create new type(sub type):

const SubType = SimpleLib.extend(proto);
const instance = new SubType();

How to write the d.ts file?

You could use a generic, something like:

declare type Constructor<T> = new (...args: any[]) => T;

function extend<T extends Constructor>(ConstructorToExtend: T) => T;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM