Skip to content

Documentation: literal "types" #18102

Closed
Closed
@bodawei

Description

@bodawei

Code

Try the following out at https://www.typescriptlang.org/play/index.html (sadly, this is too long to include a sharable link)

let num1: 1;
let num2: 2;
let num3: typeof num2;
num3 = num2;
num3 = num1;

Expected behavior:
This works exactly as expected, such that there's an error on the second assignment to num3.

I don't easily see something in your doc that mentions this is possible. It is probably implicit in various places, as it is particularly useful with some unions. Seems like calling this out explicitly would be valuable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpecIssues related to the TypeScript language specification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions