Skip to content

Possible regression in typechecker for Required type #48157

Closed
@Smrtnyk

Description

@Smrtnyk

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions