Skip to content

The issue with the order of inference #57591

Not planned
Not planned
@LiST-GIT

Description

@LiST-GIT

πŸ”Ž 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

Activity

fatcerberus

fatcerberus commented on Mar 1, 2024

@fatcerberus

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

LiST-GIT

LiST-GIT commented on Mar 1, 2024

@LiST-GIT
Author

My meaning is to wait for the inference to complete.

RyanCavanaugh

RyanCavanaugh commented on Mar 1, 2024

@RyanCavanaugh
Member

That's not a thing

RyanCavanaugh

RyanCavanaugh commented on Mar 1, 2024

@RyanCavanaugh
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

LiST-GIT commented on Mar 2, 2024

@LiST-GIT
Author

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 commented on Mar 4, 2024

@RyanCavanaugh
Member

Duplicate #47599

typescript-bot

typescript-bot commented on Mar 7, 2024

@typescript-bot
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @LiST-GIT@fatcerberus@RyanCavanaugh@typescript-bot

        Issue actions

          The issue with the order of inference Β· Issue #57591 Β· microsoft/TypeScript