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

Function generic unmatched: Matching hehavior is difference between arrow functions and normal function #58630

Closed
HoikanChan opened this issue May 23, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@HoikanChan
Copy link

HoikanChan commented May 23, 2024

πŸ”Ž Search Terms

Function generic unmatched

πŸ•— Version & Regression Information

  • This is marybe bug?
  • The versions is 5.4.5

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.4.5#code/KYDwDg9gTgLgBDAnmYcDKMCGNgDECuAdgMYwCWEhAPBtsAHxwC8cAFAFBxdwDOAXOiw4ANJ24A6SZigBzfnEyFEAbQC67AJTNGixAG527UJFgJkqAGr5QGaMADyYcpR5UxXWiPdwAshAAm+AA2wDyijCwA3t48QsAA-AKeqAA+bKxaTIzJWmmRbBpJcXAAvgbccAC2+EIUhDyJcABKwMTQ-lSxUGSEMsKCdAQkztTJ9PTl3JUBwaGN0RUVygDWcD1wy8CIEABmvjMhPKoCVjYwdo4jrn6Bhyuq-YTAAG7AUPTeZewlhsbQ8DsiKQ6nBiFBgHRbOC3BVknBQDhCP4eM1Wu1OjBur1+kRloQIAB3Qj0UQVG6zFEI4BIlEtNpQDpdHp9VH0xmY5k4wh4wnEknseisCBOOryU4gKEOEUuGhxfrkw70LTRH7sNr1eCxOzMUHgyHncGsBbcWJ0DJwfLgmD4KCEC1wABG0gATAIAIylUqkqY1bCigT5HrEASsU04N3OgDMmUYYeAEcj4idUGdAGpU17vNNbqEA94KjsIBA84tS3AAPTl3hxEMxtj5ZOuuAekoafqVuAAFQAFmQUVVsMRuwhu6g45My9wO3GBIDhiDzcbJ1wOxUrTa7Q2Xe7ShPlx2Su2qwAhGojvugxQAchg+bLccXd+XXHXtvtjZ3X2fXEPFarin8LtexRYhr1vb8-2rOgA0dbdmy9OAn0WapahcGCgxDOM6zjJMXXTTMkMPT5RFbAwgA

πŸ’» Code

export type StateFunction<State> = (
    s: State,
    ...args: any[]
) => any;

export type VuexStoreOptions<
    State,
    Modules,
> = {
    state?: State | (() => State) | { (): State };
    mutations?: Record<string, StateFunction<State>>;
    modules?: {
        [k in keyof Modules]: VuexStoreOptions<Modules[k], never>
    };
}

export function createStore<
    State extends Record<string, unknown>,
    Modules extends Record<string, Record<string, unknown>>,
>(options: VuexStoreOptions<State, Modules>) {
}

const store = createStore({
    state() { return { bar2: 1 } },
    mutations: { inc: (state123) => state123.bar2++ },
    modules: {
        foo: {
            // state: () => ({ bar2: 1 }), // This  match the state;
            // state: function () {
            //     return { bar2: 1 };
            // }, // But this can't
            state() {
                 return { bar2: 1 };
            }, // and This can't
            // state: { bar2: 1 }, 
            mutations: { inc: (state) => state.bar2++ },

        },
    },
});

πŸ™ Actual behavior

If use arrow function or obj method function to declare the state in modules.foo

Got error:
'state.bar2' is of type 'unknown'.

But arrow function won't.

πŸ™‚ Expected behavior

No matter which one i use to declare the fucntion ( arrow function, method function or just function),
the state can be known in mutations param

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 7, 2024
@RyanCavanaugh
Copy link
Member

See #47599

@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 Jun 10, 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

3 participants