Microsoft/TypeScript
Voir sur GitHubGeneric indexed access on type with optional properties doesn't include `undefined` in its constraint in `exactOptionalPropertyTypes`
Open
#57 023 ouverte le 11 janv. 2024
Domain: flag: exactOptionalPropertyTypesHelp WantedPossible Improvement
Métriques du dépôt
- Stars
- (48 455 stars)
- Métriques de merge PR
- (Merge moyen 6j 17h) (9 PRs mergées en 30 j)
Description
🔎 Search Terms
exactOptionalPropertyTypes optional generic indexed access undefined missing contextual constraint eopt
🕗 Version & Regression Information
- This changed in 5.3.0-dev.20230914
⏯ Playground Link
💻 Code
// @exactOptionalPropertyTypes: true
interface XStateConfiguration {
theme?: "auto" | "dark" | "light";
viewColumn?: "beside" | "active";
}
declare function getVscodeConfiguration<T>(section: string): T | undefined;
export function getConfiguration<Name extends keyof XStateConfiguration>(
name: Name,
): XStateConfiguration[Name] {
const genericAssignabilityTest: XStateConfiguration[Name] = undefined; // error
return getVscodeConfiguration(name); // error
}
const concreteAssignabilityTest: XStateConfiguration[keyof XStateConfiguration] = undefined; // ok
🙁 Actual behavior
undefined is not assignable to an indexed access like this in expression space
🙂 Expected behavior
I'd expect this to typecheck OK - just like the concrete example
Additional information about the issue
No response