🔎 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
exporttypeStateFunction<State>=(s: State,
...args: any[])=>any;exporttypeVuexStoreOptions<State,Modules,>={state?: State|(()=>State)|{(): State};mutations?: Record<string,StateFunction<State>>;modules?: {[kinkeyofModules]: VuexStoreOptions<Modules[k],never>};}exportfunctioncreateStore<StateextendsRecord<string,unknown>,ModulesextendsRecord<string,Record<string,unknown>>,>(options: VuexStoreOptions<State,Modules>){}conststore=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'tstate(){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
🔎 Search Terms
Function generic unmatched
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/KYDwDg9gTgLgBDAnmYcDKMCGNgDECuAdgMYwCWEhAPBtsAHxwC8cAFAFBxdwDOAXOiw4ANJ24A6SZigBzfnEyFEAbQC67AJTNGixAG527UJFgJkqAGr5QGaMADyYcpR5UxXWiPdwAshAAm+AA2wDyijCwA3t48QsAA-AKeqAA+bKxaTIzJWmmRbBpJcXAAvgbccAC2+EIUhDyJcABKwMTQ-lSxUGSEMsKCdAQkztTJ9PTl3JUBwaGN0RUVygDWcD1wy8CIEABmvjMhPKoCVjYwdo4jrn6Bhyuq-YTAAG7AUPTeZewlhsbQ8DsiKQ6nBiFBgHRbOC3BVknBQDhCP4eM1Wu1OjBur1+kRloQIAB3Qj0UQVG6zFEI4BIlEtNpQDpdHp9VH0xmY5k4wh4wnEknseisCBOOryU4gKEOEUuGhxfrkw70LTRH7sNr1eCxOzMUHgyHncGsBbcWJ0DJwfLgmD4KCEC1wABG0gATAIAIylUqkqY1bCigT5HrEASsU04N3OgDMmUYYeAEcj4idUGdAGpU17vNNbqEA94KjsIBA84tS3AAPTl3hxEMxtj5ZOuuAekoafqVuAAFQAFmQUVVsMRuwhu6g45My9wO3GBIDhiDzcbJ1wOxUrTa7Q2Xe7ShPlx2Su2qwAhGojvugxQAchg+bLccXd+XXHXtvtjZ3X2fXEPFarin8LtexRYhr1vb8-2rOgA0dbdmy9OAn0WapahcGCgxDOM6zjJMXXTTMkMPT5RFbAwgA
💻 Code
🙁 Actual behavior
If use arrow function or obj method function to declare the state in
modules.fooGot 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