我已经在 .d.ts 中声明了命名空间,它应该是全局可用的,如下所示:
/src/typings/content.d.ts
import * as something from 'something';
declare namespace Content {
...
type Object = internal.Object;
}
Run Code Online (Sandbox Code Playgroud)
我想将此命名空间用于 TSX 文件中的接口:
import * as React from 'react';
interface ExampleComponentProps {
example: Content.Object;
}
export const ExampleComponent: React.FunctionComponent<ExampleComponentProps> = ({ example }) => {
return <div>{example}</div>;
};
Run Code Online (Sandbox Code Playgroud)
打字稿现在告诉我: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, …Run Code Online (Sandbox Code Playgroud)