-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Cannot infer type in generic Readonly #14360
Labels
Fixed
A PR has been merged for this issue
Comments
Hey: @ahejlsberg @yuit @DanielRosenwasser @mhegazy This is biting us pretty hard on the React typings for DefinitelyTyped. Here is another example: interface Props {
callback?: (v: number) => void;
}
class Component<P> {
protected propsReadonly: Readonly<P>;
protected propsWritable: P;
}
abstract class AbstractComponent<P extends Props> extends Component<P> {
public doStuff() {
const callbackReadonly = this.propsReadonly.callback; // (P & { children: Component<any>[]; })["callback"]
const callbackWritable = this.propsWritable.callback; // ((v: number) => void) | undefined
if (callbackReadonly) {
callbackReadonly(5); // ERR: Cannot invoke an expression whose type lacks a call signature. Type '((v: number) => void) | undefined' has no compatible call signatures.
}
if (callbackWritable) {
callbackWritable(5); // OKAY
}
}
}
class OtherComponent extends Component<Props> {
public doStuff() {
const callbackReadonly = this.propsReadonly.callback;
if (callbackReadonly) {
callbackReadonly(5); // OKAY
}
}
} |
ghost
mentioned this issue
May 1, 2017
RyanCavanaugh
added
the
Needs Investigation
This issue needs a team member to investigate its status.
label
May 24, 2017
This should be working as expected in latest. fixed by #15576 |
mhegazy
added
Fixed
A PR has been merged for this issue
and removed
Needs Investigation
This issue needs a team member to investigate its status.
labels
May 26, 2017
Thank you |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
TypeScript Version: 2.2.1
Code
Note that there is no
Object is possibly 'undefined'
message here.Expected behavior:
After
if
check method should be considered defined.Actual behavior:
Member type is not inferred correctly.
The text was updated successfully, but these errors were encountered: