gpt4 book ai didi

reactjs - typescript 找不到在全局 .d.ts 文件中声明的命名空间

转载 作者:行者123 更新时间:2023-12-04 17:21:39 25 4
gpt4 key购买 nike

我已经在 .d.ts 中声明了命名空间,它应该是全局可用的,如下所示:

/src/typings/content.d.ts

import * as something from 'something';

declare namespace Content {

...

type Object = internal.Object;
}
我想将此命名空间用于 TSX 文件中的接口(interface):
import * as React from 'react';

interface ExampleComponentProps {
example: Content.Object;
}

export const ExampleComponent: React.FunctionComponent<ExampleComponentProps> = ({ example }) => {
return <div>{example}</div>;
};
现在 typescript 告诉我: Cannot find namespace 'Content' .
我的 tsconfig 看起来像这样:
{
"compilerOptions": {
// General settings for code interpretation
"target": "esnext",
"module": "commonjs",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"noEmit": true,
"noEmitOnError": true,
"removeComments": false,
"resolveJsonModule": true,

"baseUrl": "./src",
...
},
"include": [
"./src/typings/*.d.ts",
"./src/**/*"
]
}

最佳答案

查看此 other issue

If your file has top-level import or export statement it is consideredas a module. All its' content (types, interfaces, etc.) you areinterested in needs to be exported explicitly.

关于reactjs - typescript 找不到在全局 .d.ts 文件中声明的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65792106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com