简体   繁体   English

如何在打字稿中返回新的Type?

[英]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): 我正在尝试为lib编写一个d.ts文件,该文件提供了extend创建新类型(子类型)的静态方法:

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

How to write the d.ts file? 如何写d.ts文件?

You could use a generic, something like: 您可以使用通用名称,例如:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Typescript 中返回 NonNullable 类型? - How can I return a NonNullable type in Typescript? 当我在 Typescript 中传递给函数时,如何返回相同的类型? - How can I return the same type as I pass into a function in Typescript? 如何解压返回类型为 Typescript 并可能是数组? - How can I unpack a return type that is a Typescript union and may be an array? 如何使用Typescript为$ http调用指定返回类型? - How can I specify a return type for a $http call with Typescript? 如何在Typescript接口中为函数定义void的返回类型? - How can I define a return type of void for a function in a Typescript interface? 如何根据 Typescript 中的参数控制返回类型? - How can I control the return type based on an argument in Typescript? 在 Typescript 中,如何指定可以返回多种类型的函数的返回类型? - In Typescript, how can I specify the return type of a function that can return multiple types? Typescript:如何根据参数类型获取 function 的返回类型? - Typescript: How can I get return type of function based on argument type? 如何使用 TypeScript 定义文件将新类型 Map 转换为元组类型的元素? - How Can I Map a New Type to an Element of a Tuple Type using a TypeScript Definition File? typescript 可以将所有 function 签名/重载的返回类型更改为新类型的实用程序类型 - typescript util type that can change the return type of all function signatures/overloads to a new type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM