Here is the method signature I am working with:
class CustomClass<T> {
sanitize (value: unknown): ReturnType<T>
sanitize (value: unknown[]): ReturnType<T>[]
sanitize (value: unknown | unknown[]): ReturnType<T> | ReturnType<T>[] {
// ...
}
}
type ReturnType<T> =
T extends String ? string
: T extends Number ? number
: T extends Boolean ? boolean
: T
Despite how I try to use this method, the IntelliSense feature does not recognize that it should return an array:
const exampleOne = new CustomClass<Number>().sanitize('5') // returns a number
const exampleTwo = new CustomClass<Number>().sanitize(['5']) // returns a number instead of a number[]
Is there something I'm missing or doing incorrectly here?