Skip to content
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

Possible regression in typechecker for Required type #48157

Closed
Smrtnyk opened this issue Mar 7, 2022 · 3 comments · Fixed by #48273
Closed

Possible regression in typechecker for Required type #48157

Smrtnyk opened this issue Mar 7, 2022 · 3 comments · Fixed by #48273
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Smrtnyk
Copy link

Smrtnyk commented Mar 7, 2022

Bug Report

Since upgrade to 4.6 from 4.4 I have an error with Required type
full repro here
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChkHIBGcUA-AFzIDOYUoA5rgL664wCuICYw6IyGJgA8AFWQQAHpBAATasgDWEAJ7oYaTAD4AFAAco6PVVEAaQVQBKEAI4dgUCLOEZ0WgJQ58hElB0wAbQMjAF13AG4WNk5uXn5iUh0wKlp6EAZPPEJkBH5qdAAbCAA6AvQGJIiWIA

The error was not happening on 4.4 and seems like also not in 4.5.
I didn't really see something obvious in release notes on what would cause this change.

🔎 Search Terms

Went through issues in ts repo to see if there was something already open

🕗 Version & Regression Information

4.6

Please keep and fill in the line that best applies:
-->

  • This is a crash
  • This changed between versions 4.4__ and 4.6___

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Foo {
    bar?: string
}

function foo<T extends keyof Foo>(prop: T, f: Required<Foo>) {
    bar(f[prop]);
}

function bar(t: string) {
    console.log(t);
}

🙁 Actual behavior

It complains that f[prop] can be undefined, but it is wrapped in Required which should have all keys from Foo as non optional

🙂 Expected behavior

Well, I guess it should not complain about undefined, if I properly understand the meaning of the Required generic

@DerGernTod
Copy link

this only happens with strictNullChecks enabled, in case this is of any help

@RyanCavanaugh
Copy link
Member

Bisected to #47953

@ahejlsberg
Copy link
Member

This and #48246 are caused by the same core issue. We need to exclude mapped types with optionality modifiers and/or as clauses from the new constraint logic introduced in #47370.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
5 participants