【发布时间】:2021-05-06 03:42:58
【问题描述】:
我有两个全局类型文件emotion.d.ts 和global.d.ts,它们不再被拾取。
目前使用情感主题并在emotion.d.ts 中创建了一个全局类型文件,如下所示:
import "@emotion/react";
declare module "@emotion/react" {
export interface Theme {
platform: PlatformType;
colors: {
D1: string;
D2: string;
D3: string;
D4: string;
D5: string;
};
categoryColors: {
GreenGradient: string;
BlueGradient: string;
PurpleGradient: string;
};
}
}
一切正常,但后来我在扩展 Window 时不得不使用一些全局类型。所以我创建了如下所示的 global.d.ts 文件:
declare interface Window {
Intercom: (
action: string,
payload?: { [key: string]: string | number | boolean },
) => void;
}
declare interface Document {
documentMode?: number;
}
但是,现在当我运行应用程序时,它找不到任何类型。我的 TS 配置如下所示:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"noFallthroughCasesInSwitch": true,
"typeRoots": ["./src/global.d.ts", "./src/emotion.d.ts"]
},
"include": ["src", "src/global.d.ts", "src/emotion.d.ts"]
}
还应注意,尽管在键入 VS 代码时类型确实出现在自动完成中
【问题讨论】:
-
好的,我解决了情绪问题。我的主题文件中仍然有一些使用情感 9 样式的不正确的情感导入。但是,当我重新添加全局类型文件时,情绪会被拾取,但不再是全局类型
-
嗨,AlexderKaran,你终于解决了这个问题吗?
-
嗨@Tirias,我做到了。抱歉完全忘记了这一点。将添加一个答案
标签: reactjs typescript create-react-app emotion