Array.prototype.find 接口扩展在包含模块时引发问题

Array.prototype.find Interface Extension raise issues when including Module

就我要学习 Typescript 而言,我遇到了一个问题。 首先,我在我的单曲app.ts中实现了这个。由于多种原因,我正在这样做!

我的项目代码越来越大,我决定创建我的第一个模块。我创建了一个名为 whatever.ts 的新文件:

export class Foo{...}

我在我的 app.ts 中导入这个模块,如下所示:

import * as whatever from './whatever'
let Foo = new whatever.Foo();

但在这一点上,我以前的 看起来给我的旧代码带来了一些麻烦。

class KeyValuePair<T, U> {
    public key: T;
    public value: U;

    constructor(key: T, value: U) {
        this.key = key;
        this.value = value;
    }
}

class Dictionnary<T, U> {
    private _keyValuePairs: Array<KeyValuePair<T, U>>;

    constructor() {
        this._keyValuePairs = new Array<KeyValuePair<T, U>>();
    }
...
}

每次我使用数组 function/method 智能感知都在尖叫:

[ts] Property 'xxx' does not exist on type 'Array< KeyValuePair< T, U >>.'

any

每次我尝试使用时都会发生这种情况:

this._keyValuePairs.splice(...
this._keyValuePairs.indexOf(...
this._keyValuePairs.length
for (let kvp of this._keyValuePairs) {...

如果您需要示例,请尝试使用此方法:(此方法也有其他广告)

public keys(): Array<T> {
    let keys = new Array<T>();

    for (let kvp of this._keyValuePairs) {
        keys.push(kvp.key);
    }
    return keys;
}

如果我不导入模块,一切正常。我的第一个模块失败了吗?这个问题是已知的吗? (:我没有在上面找到任何东西。)或者他们是用多个文件对我的应用程序进行编码的一种很好且正确的方法,还是我只是卡住了并且只要我将使用它就必须在一个文件中进行编码51=] 分机 ?

谢谢。

玩 tsconfig.json,像这样定位 es5 :

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "module": "commonjs", 
        "target": "es5"
    }
    ...