look this
class Demo<T> {
get<K extends keyof T>(key?: K): K extends undefined ? Partial<T> : T[K] {
const res: Partial<T> = {}
if (key) {
return res[key]
} else {
return res
}
}
}
This code does not work
I whant:
- if key == undefined, return
Partial<T>
- esle return
T[K]
How can i do this?