-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
Keywords: any, null, undefined, enum, assign, assignable, assignability, permissive, strict
From the spec:
S is assignable to a type T, and T is assignable from S, if S has no excess properties with respect to T (3.11.5) and one of the following is true:
- S and T are identical types.
- S or T is the Any type.
- S is the Undefined type.
- S is the Null type and T is not the Undefined type.
- S or T is an enum type and the other is the primitive type Number.
Why is:
- S assignable to T, if S is
anyand T is notany? - S assignable to T, if S is a
numberand T is an enum? Because enum <: number, T should be assignable to S, but why is the reverse true? And why is this not the case for string enums? S assignable to T, if S is(this was a Playground bug where strictNullChecks wasn't actually applied)undefined?S assignable to T, if S isnulland T is notundefined?
Have you guys considered a flag to opt out of some or all of these behaviors? Or are there real uses cases for them besides interop with untyped JS (or TS in non-strict mode)? I read through the spec and searched issues, but had trouble finding a discussion of why TS made these design decisions.
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code