-
Notifications
You must be signed in to change notification settings - Fork 750
Open
Description
TSGO eagerly resolve the type of inferred function Expression. for simplicity the example shows how keyof TestInterface is resolved to never (but is wrong as TestInterface could be augmented), but the issue is not limited to just keyof empty interfaces. The eager resolution happens to both params and return types of the function.
This leads to a whole set of issues (for example const getClient = (config: Simplify<AxiosConfig>) => ,,, would resolve config to a object literal that also use some internal types in axios making getClient not portable.
if the function expression type is explicitly defined the problem does not appear.
Steps to reproduce
export interface TestInterface {}
export const inferredFunction = function (): Record<keyof TestInterface, string> {return {} as any}
export const explicitFunction: () => Record<keyof TestInterface, string> = function (): Record<keyof TestInterface, string {return {} as any}
export const inferredArrowFunction = (): Record<keyof TestInterface, string> => ({}) as any;
export const explicitArrowFunction: () => Record<keyof TestInterface, string> = () => ({}) as any;
export function functionDeclaration() :Record<keyof TestInterface, string> { return {} as any}Behavior with typescript@5.9
export interface TestInterface {}
export declare const inferredFunction: () => Record<keyof TestInterface, string>;
export declare const explicitFunction: () => Record<keyof TestInterface, string>;
export declare const inferredArrowFunction: () => Record<keyof TestInterface, string>;
export declare const explicitArrowFunction: () => Record<keyof TestInterface, string>;
export declare function functionDeclaration(): Record<keyof TestInterface, string>;Behavior with tsgo
export interface TestInterface {}
export declare const inferredFunction: () => Record<never, string>;
export declare const explicitFunction: () => Record<keyof TestInterface, string>;
export declare const inferredArrowFunction: () => Record<never, string>;
export declare const explicitArrowFunction: () => Record<keyof TestInterface, string>;
export declare function functionDeclaration(): Record<keyof TestInterface, string>;Metadata
Metadata
Assignees
Labels
No labels