short tale
const xyz = (a:never):number=>1
type b = ReturnType< typeof xyz> //any
const xyz2 = (a:number, b:never):number=>1
type b2 = ReturnType< typeof xyz2> //any
If any parameter type is never, the ReturnType becomes any. Is there a solution to this?
lengthy tale (for those interested)
I've developed a utility type that enforces no undefined values for partial object members, empty objects, or excess object members, and it's working flawlessly
type _NoExcessEmptyUndefined<M, T> = M extends T
? keyof M extends keyof T
? keyof M extends never
? never
: undefined extends M[keyof M]
? never
: M
: never
: never
type something = {a?:number,b:boolean,c:string}
const xyz = <M extends something>(data:_NoExcessEmptyUndefined<M,something>):number=>1
const emptyObject = {}
const undefinedPartial = {a:undefined,b:true,c:"1"}
const excessMember = {b:true,c:"1",d:1}
xyz(emptyObject) // error if empty object
xyz(undefinedPartial) // error if partial member is undefined
xyz(excessMember) // error if excessMember
const success1 = {b:true,c:"1"}
const success2 = {a:1, b:true,c:"1"}
xyz(success1) // no error
xyz(success2) // no error
type haha = ReturnType<typeof xyz> // haha is any <-- problem
type hihi = Parameters<typeof xyz>[0] // hihi is never