我已经在 .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 considered as a module. All its' content (types, interfaces, etc.) you are interested in needs to be exported explicitly.
关于reactjs - typescript 找不到在全局 .d.ts 文件中声明的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65792106/