wangdoc / typescript-tutorial

TypeScript 教程
https://wangdoc.com/typescript
2.43k stars 256 forks source link

第19章 关于补充声明Window全局对象属性的问题 #91

Closed ArisLittle closed 9 months ago

ArisLittle commented 9 months ago

阮老师您好。我是您的一名小读者。原文,在 ./docs/declare.md

https://github.com/wangdoc/typescript-tutorial/blob/d8b2606434740847951c9ee3ff5497203e6c575f/docs/declare.md?plain=1#L305

下面的示例是为 window 对象添加一个属性`myAppConfig`。

```typescript
export {};

declare global {
  interface window {
    myAppConfig: object;
  }
}

const config = window.myAppConfig;
```

declare global 里 interface 后面的 window 的首字母 w 似乎需要大写,才能让 TS 识别接口类型。我这边 TS 版本是5.3.2。不知道这算不算一个问题呢?

ruanyf commented 9 months ago

谢谢指出,已经更正。