[3.5.1] Type 'NonNullable<Partial<Config>[T]>' is not assignable to type 'Config[T]' #31675
Labels
Fix Available
A PR has been opened for this issue
Needs Investigation
This issue needs a team member to investigate its status.
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
TypeScript Version: 3.5.1, 3.6.0-dev.20190530
Search Terms:
partial nonnullable generic mapped strictNullChecks
Code
Expected behavior:
No error
Actual behavior:
with
strictNullChecks: true
Playground Link:
https://www.typescriptlang.org/play/index.html#src=interface%20Config%20%7B%0D%0A%20%20string%3A%20string%0D%0A%20%20%2F%2F%20There%20need%20to%20be%20different%20types%20in%20here%20for%20the%20error%20to%20occur%0D%0A%20%20number%3A%20number%0D%0A%7D%0D%0A%0D%0Afunction%20getConfigOrDefault%3CT%20extends%20keyof%20Config%3E(%0D%0A%20%20userConfig%3A%20Partial%3CConfig%3E%2C%0D%0A%20%20key%3A%20T%2C%0D%0A%20%20defaultValue%3A%20Config%5BT%5D%0D%0A)%3A%20Config%5BT%5D%20%7B%0D%0A%20%20const%20userValue%20%3D%20userConfig%5Bkey%5D%20%2F%2F%20Partial%3CConfig%3E%5BT%5D%0D%0A%20%20const%20explicitAssertion%20%3D%20userConfig%5Bkey%5D%20as%20Config%5BT%5D%20%7C%20undefined%0D%0A%0D%0A%20%20%2F%2F%20Partial%3CConfig%3E%5BT%5D%20-%20already%20incorrect%20in%203.4.5%3F%0D%0A%20%20const%20simpleCheck%20%3D%20userValue%20%3F%20userValue%20%3A%20defaultValue%0D%0A%0D%0A%20%20%2F%2F%203.4.5%3A%20Config%5BT%5D%0D%0A%20%20%2F%2F%203.5.1%2C%203.6.0-dev.20190530%3A%20Config%5BT%5D%20%7C%20NonNullable%3CPartial%3CConfig%3E%5BT%5D%3E%0D%0A%20%20const%20assertedCheck%20%3D%20userValue%20%3F%20userValue!%20%3A%20defaultValue%0D%0A%0D%0A%20%20return%20assertedCheck%0D%0A%7D%0D%0A
(error does not occur there - which TS version does the playground run on?)
Related Issues:
These issues looked similar but were already reported for earlier versions of TypeScript:
#27456
#30706
The text was updated successfully, but these errors were encountered: