-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Default Values for String Literal Types #7223
Labels
Comments
This works: interface Foo {
bar: "fizz" | "buzz"
}
class Bar implements Foo {
bar: "fizz" | "buzz" = "fizz";
} |
blink1073
changed the title
Allow Stricter Subtypes for String Literal Types
Allow Default Values for String Literal Types
Feb 24, 2016
Another example: class Foo {
bar: "fizz" | "buzz";
}
class Bar1 extends Foo {
constructor() {
super();
this.bar = "fizz"; // okay
}
}
class Bar2 extends Foo {
bar = "fizz"; // fail
} |
mhegazy
added
Suggestion
An idea for TypeScript
Committed
The team has roadmapped this issue
labels
Mar 28, 2016
Or #10610 |
I ran the original code through the 2.0.2 compiler, and the error remains. |
The message has changed to: test.ts(6,7): error TS2415: Class 'Bar' incorrectly extends base class 'Foo'.
Types of property 'bar' are incompatible.
Type 'string' is not assignable to type '"fizz" | "buzz"'. |
Ah, fair enough. |
mhegazy
added
In Discussion
Not yet reached consensus
and removed
Committed
The team has roadmapped this issue
labels
Sep 21, 2016
Duplicate #10570 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript Version:
1.8.2.
Code
Expected behavior:
Bar.bar
is initialized to"fizz"
;Actual behavior:
Type 'string' is not assignable to type '"buzz"'
The text was updated successfully, but these errors were encountered: