-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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";
} |
Another example: class Foo {
bar: "fizz" | "buzz";
}
class Bar1 extends Foo {
constructor() {
super();
this.bar = "fizz"; // okay
}
}
class Bar2 extends Foo {
bar = "fizz"; // fail
} |
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. |
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: