Skip to content

Docs: Extend a documentation on how casting works #35817

@Hell4Ge

Description

@Hell4Ge

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

No one assigned

    Labels

    UnactionableThere isn't something we can do with this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions