javascript - Typescript 文件找不到 .d.ts 文件中定义的声明
问题描述
我正在尝试为我的打字稿插件声明一些全局窗口函数。这些函数是在浏览器中定义的,我希望它们也可以在代码中声明。
出于某种奇怪的原因,我的代码无法从该文件中找到这些声明。声明位于 @types/globals.d.ts 文件中。
我是否需要配置 tsconfig.json 文件或类似的东西。似乎无法从其他任何地方找到直接的答案。
以防万一,这是我的 tsconfig.json 文件
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"strict": true,
"sourceMap": true,
"allowJs": true,
"moduleResolution": "node"
}
}
全局.d.ts
索引.ts
这是错误消息
提前致谢。
解决方案
正确的解决方案是重新定义窗口界面。现在其余的文件会自动检测类型。
declare global {
interface Window {
section: string;
__t: (string: string) => string;
apiSessionKey: string;
companyData: CompanyData;
conf_dateformat: string;
country: string;
customerCode: string;
decimalSymbol: string;
employeeEmail: string;
employeeID: number;
employeeName: string;
formAttributes: any[];
gdprFeaturesEnabled: boolean;
isExistingRecord: boolean;
page_lang: string;
priceDecimals: number;
recordID: number;
subsection: string;
thousandsSeparator: string;
userGroupID: number;
userGroupName: string;
userID: number;
userName: string;
}
}
推荐阅读
- mysql - 如何使用 Node 从 MySQL 数据库中获取数据
- python - 简单Flask python后端中POST方法的KeyError
- java - 如何从字符串中解析时间?
- python - 带有 seaborn 的 Matplotlib 不显示西里尔符号
- eclipse - Eclipse 2019 黑色背景
- java - 如何从第二个位置删除一个线性布局子?
- android - 一旦登录成功,Android 初始登录屏幕然后使用片段在屏幕之间滑动
- vue.js - 将 Vue 组件转换为 base64
- git - git Untracked Files 防止合并后保留本地更改
- excel - VBA O365 Mac Excel 复制和带有链接的 Word PasteSpecial = True 问题