-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
UnactionableThere isn't something we can do with this issueThere isn't something we can do with this issue
Description
Search Terms
- cast
Suggestion
A docs should clear how casting works since it's not like in any other language which I will explain later
Use Cases
- The docs
Examples
According to https://www.typescriptlang.org/play/
This code:
const someStringNumber: string = '100';
const someNumber: number = someStringNumber as unknown as number;
console.log(typeof someNumber); // string
converts into
"use strict";
const someStringNumber = '100';
const someNumber = someStringNumber;
console.log(typeof someNumber); // string
Which does not make any sense, it does nothing and makes weird bugs during runtime.
It's the same here:
let foo: string = "100";
let xyz: number = <number><unknown>foo;
This compiles into
var foo = "100";
var xyz = foo;
Metadata
Metadata
Assignees
Labels
UnactionableThere isn't something we can do with this issueThere isn't something we can do with this issue