Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The issue with the order of inference #57591

Closed
LiST-GIT opened this issue Mar 1, 2024 · 7 comments
Closed

The issue with the order of inference #57591

LiST-GIT opened this issue Mar 1, 2024 · 7 comments
Labels
Duplicate An existing issue was already created

Comments

@LiST-GIT
Copy link

LiST-GIT commented Mar 1, 2024

πŸ”Ž Search Terms

Infer, Generics

πŸ•— Version & Regression Information

5.5.0-dev.20240229

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240229#code/C4TwDgpgBAogbhAdsAKuaBeKiCuBbAIwgCcoAfKAZ2GIEtEBzcqkQgewBsBuAKFElgJkAeTDBabRJShYA3gF9e-aPCTAAIhADGHAIbFd4ydKwAlbW2IATADy7EIADRR7IANoBdAHxL0gtZQ2PFAhUCiOwaEwEaGwMFAQAB7ASFbSqsiaOvqGElIysAnJqelCGtp6Bkb5APyFAGRQslBuygBc-shokB4drp5Q8lAdza3oHRmo6L0uDgPyPF4FspEhbgByUPRQANYQIGwAZnEeNR0AFOdakinJHeEJZaLVlBNPYnmUzgB0v-oMrziGw8AEoZEs4GxaFYQbwho0UAALWiUboQGyQ6E+Hg8Q44RBaapQKwQQ70dGrKDqQy6IopRBpKBsAgAK20wGW8hioQAshBgIi2IykvTGeZrtY7A5nAAxfGEvJLORcyniiC0OC6AgcaAikqdcrZKqfTnckIASSkwHsWkwVJpUEafIFQq+i3ObA+xhGlMQujwEA61DojDNUGUlDOTUpsTVGq1Oqjcc12ogYZVlKsNKj1OtYYDLrSUedgsZCORqPQNkt1BtEC8+d0DFoWij510HRr1oJEDBGAhUKsYfoKWItrElij6zYlsOJBsk0CXbrzmTCfrDagAHot1Bp7OSFtpMQIABHHC0E9WcNsBJSHAn8OI6ASk+E8N+I5QFk-lnfXTfDw8hgs0ig4iSZKIBA5wrLEfoBh0ADkugoYhYYRj6sSxto6opjqIxDLo0iwVhpGIRAZSIR0nhhqRISIb+LJUS0HbYPgRDEB4tF0YhWh8VozFuAQQY0PQDBcTGPH8VoACMgnCVQomMBJdGDOmYZZtaFwkaRBB6QpNA4GmkkhAwZkMBcfZLKB3EhDs9k7OcIEhDuUDmscAoolAeIEkSXnXHgAbIBA15sDgwDOHgTYtke2BsByUEhSFJlYZ5lDfPpBApbEaXfA5OwpSqsTAWGrlRc2WhOU0anbruiC3pS5Utu2zlcrVUAgBAlCUiOJDjsAliYTxjGIVcNwis4novM4uggdlqkLaErkAHo1PNITXMFyQZfp61QJttzAN85kMHtB0inlDmFbZLiUFYY1bRFTJelIM1zapRWhCqwFcEAA

πŸ’» Code

type EventType = number | string | symbol;
type EventOptions = {};
type EventDeclarations = Record<any, any[]>;
type Events<
    T,
    E,
    EE extends EventDeclarations = E extends EventDeclarations ? E & { [type: EventType]: any[] } : { [type: EventType]: any[] }
> = {
    [N in keyof EE]?: ((context: T, eventOptions: EventOptions, ...args: EE[N]) => void);
} & ThisType<void>;

function define<
    Data extends object = {},
    Methods extends Record<any, Function> = {},
    Receivable extends EventDeclarations = {},
    Instance = Data & Methods,
>(options: {
    name: string,
    types?: {
        Receivable?: Receivable,
    },

    data?: Data,
    methods?: Methods & ThisType<Instance>,
    magic?: (a: Instance) => void,
    interceptor?: NoInfer<Events<Instance, Receivable>>, // NoInfer is required to ensure the correct type of jjjj.a.
}) { };

define({
    name: 'aaa',
    types: {
        Receivable: {} as {
            'event': [],
            'jjjj': [a: number],
            'cccc': [b: string],
            'cccc1': [b: string],
        },
    },
    data: ({
        bbbb: true,
        gggg: () => { },
        kkkk() {  // If this function is commented out, magic is not needed
            this.bbbb
            this.kkkk
        },
    }),
    // magic() { }, // no 
    magic(a) { }, // yes
    interceptor: {
        'jjjj'(context, options, a) {
                             // ^?
            context.bbbb
            context.gggg
            context.kkkk
        },
        asd(context, options, a) {
        },
    },
});

πŸ™ Actual behavior

The magic function must be added and must have parameters to be error-free.

πŸ™‚ Expected behavior

No magic function is needed.
Perhaps an explicit command could be added to ensure waiting for certain parameter inferences to complete?

interceptor?: NoInfer<Events<FinalInfer<Instance>, Receivable>> // Add FinalInfer to ensure that the Instance is the final inference.
interceptor?: NoInfer<Events<Instance, Receivable>> & FinalInfer<Instance> // Add FinalInfer to ensure that the Instance is the final inference.

Additional information about the issue

No response

@fatcerberus
Copy link

NoInfer<FinalInfer<T>> seems like a contradiction: "Don't infer from here at all, but also infer from here last"?

@LiST-GIT
Copy link
Author

LiST-GIT commented Mar 1, 2024

My meaning is to wait for the inference to complete.

@RyanCavanaugh
Copy link
Member

That's not a thing

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Mar 1, 2024
@RyanCavanaugh
Copy link
Member

We really need a minimzied repro; there's a lot going on here that doesn't seem germane to the issue being described

@LiST-GIT
Copy link
Author

LiST-GIT commented Mar 2, 2024

I removed some of the code.

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240301#code/C4TwDgpgBAogbhAdsAKuaBeKiCuBbAIwgCcoAfKAZ2GIEtEBzcqkQgewBsBuAKFElgJklADwoAfFCwBvKAG0AcgC5BSVOgC6KgBTaAxm2QQAHsBUoANFAB0tgIbEGlFXcQg5GgJRTJcNrQATbwBfXh4AMxxEPWBaQygAiHD6CBEeKAyoABE7YDsoE2AkAMooNgIAKwgYqShpYIsecW02MFjDZzr0zIDcuwB+FRy8xsyoPDsGWj1BqG07Ib7vDF9-ANHM+iLiPQg2tmJZhTYASURwkhF4NVFhu3FxKwB6J6hjs4vSWlLiCABHHC0X4BKDANgFRCUHC-UEAC2gBmIvxq-GgbHCUAqWIq1js1h4wW8slCPB4iWSiAg2mk3QyvTyOhpYzGBFZBBUNBwEA2zKgDH5DB0y0kxJ5zIA1pLxdoiRkXlAThjgLDvlBItF2ogoKqDHg8GoICC2DhgFYJlM9NrSog2MBsBBDYbabzMsrvtY2QRnS64e6peLvZkGs7CWL5ebpjK6lAGlB5SRiAdneHJpG7LLY-K2AGxlsSLt9sQVEyXQBybEVUv6QxFUxWdNdH1jeUAPX6gd5BiMpg9bI7zK7teA1gFDH7Y0HhWs-v7wZ9dkoAWr3dNUAbJd5c6DjUJvCAA

type EventType = number | string | symbol;
type Events<T> = { [N: EventType]: ((context: T, ...args: any[]) => void) };

function define<
    Data extends object = {},
>(options: {
    data?: Data,
    magic?: (a: Data) => void,
    interceptor?: NoInfer<Events<Data>>, // NoInfer is required to ensure the correct type of jjjj.a.
}) { };

define({
    data: ({
        bbbb: true,
        gggg: () => { },
        kkkk() {  // If this function is commented out, magic is not needed
            this.bbbb
            this.kkkk
        },
    }),
    // magic() { }, // error
    // magic(a) { }, // ok
    interceptor: {
        'jjjj'(context, a) {
            // ^?
            context.bbbb
            context.gggg
            context.kkkk
        },
        asd(context, a) {
        },
    },
});

@RyanCavanaugh RyanCavanaugh removed the Needs More Info The issue still hasn't been fully clarified label Mar 2, 2024
@RyanCavanaugh
Copy link
Member

Duplicate #47599

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 4, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants