Typescript: タイプをこれに参照できません(厳密モードの場合)

作成日 2017年05月23日  ·  1コメント  ·  ソース: microsoft/TypeScript



TypeScriptバージョン: 2.2.1 /毎晩(2.2.0-dev.201xxxxx)
2.3.3

コード

strictはtrueです

function test(){
    console.log(this.value);
    console.log((this as any).value);
}

let a = {
    value: 'a',
    test: test
}

a.test()

予想される行動:
サク

実際の動作:

Test.ts(2,17):エラーTS2683: 'this'には型注釈がないため、暗黙的に型 'any'があります。
Test.ts(3,18):エラーTS2683: 'this'には型注釈がないため、暗黙的に型 'any'があります。

Question

最も参考になるコメント

関数の宣言でthisタイプを指定します。

function test(this: any) {
    console.log(this.value);
}

または--noImplicitThis false切り替え

>すべてのコメント

関数の宣言でthisタイプを指定します。

function test(this: any) {
    console.log(this.value);
}

または--noImplicitThis false切り替え

このページは役に立ちましたか?
0 / 5 - 0 評価