小编Mea*_*ear的帖子

Typescript 找不到全局 .d.ts 文件中声明的命名空间

我已经在 .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)

typescript reactjs typescript-typings

7
推荐指数
1
解决办法
5544
查看次数

标签 统计

reactjs ×1

typescript ×1

typescript-typings ×1