![](/img/trans.png)
[英]TypeScript : How to fix TS7016 : Type definition not found 404
[英]Typescript no type definition found
我制作了一个在npm上发布的打字稿模块,但是我无法让智能工作。
文件结构就是这样
dist
index.js
+ others
src
index.ts
+ others
package.json
tsconfig.json
src
包含.ts
文件,而dist .js
, .d.ts
和.js.map
。
如果我这样做:
import { X } from 'my-package';
它将正常工作,没有错误,但是没有智能提示,并且消息the type definition is not found
。
但是,如果我这样做:
import { X } from 'my-package/dist';
我确实懂了。
在package.json中,我输入:
"main": "dist/index.js",
这是我的tsconfig:
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"removeComments": false, /* Do not emit comments to output. */
"strict": true, /* Enable all strict type-checking options. */
"sourceRoot": "./dist", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
"mapRoot": "./dist" /* Specify the location where debugger should locate map files instead of generated locations. */
},"exclude": [
"test/**"
]
}
您需要单独引用.d.ts
文件。 请参见TypeScript手册中的发布部分。
在你的package.json
:
{
"name": "awesome",
"author": "me",
"version": "1.0.0",
"main": "./dist/index.js",
"types": "./dist/index.d.ts"
}
注意types
键,其值指向index.d.ts
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.