-
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
Readonly for generic param doesn't work for optional properties #17005
Comments
I came across this same issue, using v. 2.5.0. Using interface Foo {
foo?: number;
}
class FooClass<P extends Foo = Foo> {
properties: Readonly<P>;
foo(): number {
const { foo = 42 } = this.properties;
return foo;
}
} Removing the generic or getting rid of interface Foo {
foo?: number;
}
class FooClass {
properties: Readonly<Foo>;
foo(): number {
const { foo = 42 } = this.properties;
return foo;
}
} and interface Foo {
foo?: number;
}
class FooClass<P extends Foo = Foo> {
properties: P;
foo(): number {
const { foo = 42 } = this.properties;
return foo;
}
} It appears that |
@mhegazy @RyanCavanaugh Hey! I am suffering from an issue that seems somewhat related to this original issue using version Seems that for a generic (that are being mapped with interface Props {
foo?: boolean;
}
class Foo<P extends Props = Props> {
props: Readonly<P> = {} as P;
myFunc() {
const { foo = false } = this.props;
// errors because the type of `foo` is narrowed to `false` and cannot be
// compared to `true`
if (foo === true) {}
}
} As per the examples from the previous issue above, removing Here's a playground link (don't forget to set Thanks in advance! |
@agubler please file a new ticket for that one. |
@mhegazy will do, thanks! |
TypeScript Version: 2.3.4 or 2.4.1
Code
Expected behavior:
no errors
Actual behavior:
Error: Property 'name' does not exist on type 'T["params"]'.
If I remove
Readonly
or get rid of generic paramT
then everything will be ok.The text was updated successfully, but these errors were encountered: