从打字稿模块自动生成index.d.ts,类型定义 [英] Auto generate index.d.ts, type definitions, from a typescript module

查看:568
本文介绍了从打字稿模块自动生成index.d.ts,类型定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将TypeScript模块保存为my-function.ts,如下所示:

If I have a TypeScript module saved as my-function.ts as follows :

export function myFunction (param: number): number { return param }

这将以任何方式编译为JavaScript,并松开其类型定义.然后,我可以创建一个index.d.ts文件来声明此模块的定义,但是重新定义/重新定义这些定义似乎有点乏味.

This will be compiled to JavaScript in whichever way and loose its type definitions. I am then able to create a index.d.ts file which declare this module's definitions, but this seems a bit tedious to redefine/redeclare the definitions.

有没有办法从my-function.ts文件自动生成类型定义到index.d.ts文件?

Are there ways to generate the type definitions automatically from the my-function.ts file to a index.d.ts file?

推荐答案

如果使用--declaration标志进行编译,TypeScript将自动为您生成.d.ts文件.

If you compile with the --declaration flag, TypeScript will automatically generate .d.ts files for you.

此模式将要求您可以看到某些类型,以便可以在您的.d.ts文件中对其进行描述.

This mode will require that you certain types are visible so that they can be described in your .d.ts files.

这篇关于从打字稿模块自动生成index.d.ts,类型定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆