Skip to content

The spec doesn't describe the newest cast semantics #12419

Closed
@dimvar

Description

@dimvar

When casting from a type A to a type B, the spec says that either A is assignable to B, or B is assignable to A. But the playground allows something more general: in some cases, as long as A and B have a common subtype, it doesn’t warn. The next example is valid.

function f(x: number | string) {
    return <number | boolean>(x);
}

The playground uses the comparable relation. The spec should be updated to include it.

Metadata

Metadata

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