How to convert string type to number type in TypeScript
This is an easy way to convert string → number in TypeScript.
let a:string = '100'; let b:any = +a;// add + to it console.log(typeof b);// displayed as number
|0 is not available.
With JS, I could convert it with |0 as follows, but it seems impossible with TS.
let abd:number = '100'|0; console.log(typeof abd);
It will be “TS2362: The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’ or an enum type.“
![株式会社CONFRAGE](https://i0.wp.com/confrage.jp/wp-content/uploads/2018/08/aaaaaaaaa-1.jpg?resize=100%2C100&ssl=1)
コメント