[英]ts-node can't find my type definition files
When I run ts-node node_modules/jasmine/bin/jasmine
I get these errors:当我运行
ts-node node_modules/jasmine/bin/jasmine
我收到以下错误:
tsc/globals.ts:7:12 - error TS2304: Cannot find name 'SugarcubeState'.
7 State: SugarcubeState;
~~~~~~~~~~~~~~
Here is that global file:这是该全局文件:
/* eslint-disable @typescript-eslint/no-explicit-any */
console.log("global.ts");
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace NodeJS {
interface Global {
State: SugarcubeState;
setup: {};
}
}
declare const State: SugarcubeState = {
variables: {}
};
declare const setup: any = {
variables: {}
};
Here is my index.d.ts:这是我的 index.d.ts:
type SugarcubeVariables = {
};
type SugarcubeState = { variables: SugarcubeVariables };
These are both in the same directory and Visual Studio code is not complaining about anything.它们都在同一个目录中,Visual Studio 代码没有抱怨任何东西。 Why can't ts-node seem to find my type definition files?
为什么 ts-node 似乎找不到我的类型定义文件?
I googled this and found this website:https://github.com/TypeStrong/ts-node#help-my-types-are-missing Following its advice, i modified my tsconfig file to have a我用谷歌搜索并找到了这个网站:https ://github.com/TypeStrong/ts-node#help-my-types-are-missing按照它的建议,我修改了我的 tsconfig 文件
"typeRoots": ["tsc"], /* List of folders to include type definitions from. */
in it, but it had no effect on the error.在其中,但它对错误没有影响。 I also tried this:
我也试过这个:
"types": ["tsc/index.d.ts"], /* Type declaration files to be included in compilation. */
But again, no difference in the errors I received.但同样,我收到的错误没有区别。 How do I get ts-node to recognize my .d.ts files?
如何让 ts-node 识别我的 .d.ts 文件?
PS: If you're wondering why I'm defining things this way, see this answer https://stackoverflow.com/a/43523944/61624 PS:如果您想知道我为什么要这样定义事物,请参阅此答案https://stackoverflow.com/a/43523944/61624
I reread that link and it appears that I need to have a very specific directory structure.我重读了那个链接,看来我需要一个非常具体的目录结构。 The problem is, it says I need but the module name in this directory structure, and given the way I wrote my index.d.ts, i have no idea what to name this directory.
问题是,它说我只需要这个目录结构中的模块名称,并且考虑到我编写 index.d.ts 的方式,我不知道该目录的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.