Typescriptが自分の利益のためにあまりにもスマートであると思われるこの面白いコンパイルエラーが発生しました。typescriptビルド:オペレータ '=='は入力できません '' = "'and'" {"'
private _currentToken: string;
....
private ParseKeyValuePair(): KeyValuePair<string, any>
{
let key = this.RemoveBracketAndQuote(this._currentToken);
this.NextToken();
if (this._currentToken != "=")
throw "Expect = sign but got " + this._currentToken;
this.NextToken();
let val: any = this.RemoveBracketAndQuote(this._currentToken);
if (this._currentToken == "{") //Compile error on this line
val = this.ParseObject();
return new KeyValuePair(key, val);
}
これは私が書いた迅速かつ汚いパーサであり、私は私がこのコンパイルエラーを取得しています2.6にTSをアップグレードした後、TS 1.7
でコンパイルしたとき、それは完璧に動作します。 TSは、最初のif文を見て、それを決定するようにそれはそう私には演算子「==」は型に適用されるカント「『=』」と「『{』」
this._currentToken
:
ビルド文字列
"="
でなければなりません。それ以外の場合は例外がスローされます。しかし実際にはthis._currentToken
はthis.NextToken()
コールによって変更され、TSはそれを予期しませんでした。Typescriptコンパイラのバグですか、私は何かここで愚かなことをしていますか?
編集:それは助け以上のものを傷つけるように、この場合にはそれが見えますが、私は
class Test { private property: string; private changeProperty(): void { this.property = "bar"; } private TestFunc(): void { if (this.property != "foo") throw "bad"; this.changeProperty(); if (this.property == "bar") //compile error console.log("good"); } }