-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionOut of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Regarding issue #1003. Given:
interface A { P: "P"; }
All of the following are valid:
var v1: A = { P: undefined };
var v2: A = { P: null };
var v3: A = { P: <any>5 };
var v4: A = { P: "P" };
But (consistent with TS 1.3) this is not, because it doesn't explicitly initialise P:
var v5: A = { };
I suggest the compiler behave as if P had been initialised, as for v4. This is the overwhelmingly likely option and avoids the redundancy of both stating the type A and repeating the definition of P.
For classes:
class C1 implements A { }
class C2 { P: "P" }
class C3 { P: "P" = "P" }
I suggest for C1 and C2 the compiler behave as for C3, for a similar reason: that's almost certain to be what I'd have to write out by hand.
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionOut of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScriptAn idea for TypeScript