-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Property type is not narrowed for readonly object in some contexts #19469
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
Comments
Seems to not produce errors in latest. can you give [email protected] a try. |
@mhegazy Yup, it is fixed for |
I am still reproduce this on 2.6.1. Is it supposed to be fixed on that version? |
I am not seeing any errors on |
declare class Maybe<A> {
static of<A>(value: A | undefined): Maybe<A>;
map<B>(f: (a: A) => B): Maybe<B>;
}
{
type User = { name: string };
const logUser = (_user: User) => {};
type State = {
user: User | undefined;
};
const fn = function<Own extends {}>(p: Readonly<Own & State>) {
const { user } = p;
Maybe.of(user).map(
user =>
// Unexpected error: Object is possibly 'undefined'.
user.name,
);
};
} |
in this example |
Would this fix the above example so the correct types would be inferred, or would I still have to workaround this by annotating |
depending on how it is implemented. but yes it would. |
TypeScript Version: 2.4.1 and 2.6.0-rc
Code
Expected behavior:
(See comments in code.)
The text was updated successfully, but these errors were encountered: