Quantcast
Channel: Y.A.M の 雑記帳
Viewing all articles
Browse latest Browse all 415

TypeScript での Type Assertion

$
0
0
document.getElementById("#input"); の戻り値は HTMLElement なので var input : HTMLInputElement = document.getElementById("#input"); とすると、キャストできないと怒られます。

Cannot convert 'HTMLElement' to 'HTMLInputElement': Type 'HTMLElement' is missing property 'setSelectionRange' from type 'HTMLInputElement'

そこで、次のように < > を使ってキャストすれば怒られなくなります。 var input : HTMLInputElement = <HTMLInputElement>document.getElementById("#input");

Viewing all articles
Browse latest Browse all 415

Trending Articles