const EventKeys = {
openItem: 'openItem',
changeActiveItem: 'changeActiveItem',
selectionToggled: 'selectionToggled',
} as const
type EventKeys = keyof typeof EventKeys
class Test<Evmt>{
subscribe<CurrentEeventKey = Evmt>(arg:CurrentEeventKey){
// In this section, the correct type is being detected
console.log(arg)
return arg
// ^?
}
}
const t1 = new Test<EventKeys>
// ^?const t1: Test<"openItem" | "changeActiveItem" | "selectionToggled">
const abc = t1.subscribe('11223')
// The type parameter should cause an error here since it should take on the constructor value
// ^? const abc: "11223"
t1.subscribe<'11223'>('11223')
// However, the type parameter should not cause an error here as it should use the supplied value instead
I attempted to pass the argument and set a default value. My intention was for the function to automatically pick up the generic type from the default value passed during the constructor call, eliminating the need to define it again. But when provided during the function call, it should accept that specific type. The inference works correctly inside the function where the type is accurate.