Looking to create a function that takes a string as input and determines whether it contains '[]' or not. If it does, the function should return a list, otherwise an object. This is what I have so far:
function customFunction<T = any>(input: string): typeof input extends `${any}[]${any}` ? Array<T> : T {
if (input.includes('[]')) {
return [] as T[]
}
return {} as T
}
Unfortunately, the function only returns a string instead of the expected type.
I am using TypeScript version 4.3.2. Can anyone assist me with this issue?