Closed
Description
Bug Report
π Search Terms
conditionally generic return type, union vs intersection, valueof etc
π Version & Regression Information
- This changed between versions 3.3.3 and 3.5
β― Playground Link
Playground link with relevant code
π» Code
export interface ConfigA {
user: string
}
export interface ConfigB {
[key: string]: number | string | boolean
}
export interface Config {
A?: ConfigA
B?: ConfigB
}
export class ConfigClass {
config: Config = {}
get(key: keyof Config) {
return this.config[key]
}
}
type ValueOf<T> = T[keyof T]
const config = new ConfigClass()
function a<K extends keyof Config>(key: K): Config[K] {
return config.get(key)
}
π Actual behavior
Type 'ConfigA | ConfigB | undefined' is not assignable to type 'Config[K]'.
Type 'ConfigA' is not assignable to type 'Config[K]'.
Type 'ConfigA' is not assignable to type 'ConfigA & ConfigB'.
Type 'ConfigA' is not assignable to type 'ConfigB'.
Index signature for type 'string' is missing in type 'ConfigA'.
π Expected behavior
I would expect no error of returning config.get(key)
within function a