Closed oskar-martensson closed 3 months ago
XState version 5
Type of emit cannot be inferred when when defining an action.
Example
setup({ types: { emitted: {} as { type: 'apple', value: string } | { type: 'banana', value: number } }, actions: { appleAction: emit({ type: 'apple', value: 'fruit' }), bananaAction: emit({ type: 'banana', value: 2 }) }, });
Type should be inferred.
Type '{ type: string; value: string; }' is not assignable to type '{ type: "apple"; value: string; } | { type: "banana"; value: number; }'.
https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240331#code/JYWwDg9gTgLgBAbzgZwKYwK5gDR1SYeAXzgDMoIQ4AiAD2RgEMZVqBuOAek7hgE8wqZAC44AVgB0ATgkBGAFDy0mMAAoE8uLwFDRGrVvyEWAEz0lGyRNsGiA5IzBgANqju4Abo2cZUohlDAAHYA5nAkAD7W-LZwdgBGjEFJjO5wXj5+cEEYIPGoUOGa4djFjADGMMAQQSKIxVqOLqgAgpXVQaJGMOo2WQ5OrmkZvvbkGIR24QCUpQZwicnJbVU1XQQ9SDH9iynD3qNwAEwzxUSlRNNs8kA
No response
@Andarist Is this the same issue as #4545 ?
XState version
XState version 5
Description
Type of emit cannot be inferred when when defining an action.
Example
Expected result
Type should be inferred.
Actual result
Type '{ type: string; value: string; }' is not assignable to type '{ type: "apple"; value: string; } | { type: "banana"; value: number; }'.
Reproduction
https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240331#code/JYWwDg9gTgLgBAbzgZwKYwK5gDR1SYeAXzgDMoIQ4AiAD2RgEMZVqBuOAek7hgE8wqZAC44AVgB0ATgkBGAFDy0mMAAoE8uLwFDRGrVvyEWAEz0lGyRNsGiA5IzBgANqju4Abo2cZUohlDAAHYA5nAkAD7W-LZwdgBGjEFJjO5wXj5+cEEYIPGoUOGa4djFjADGMMAQQSKIxVqOLqgAgpXVQaJGMOo2WQ5OrmkZvvbkGIR24QCUpQZwicnJbVU1XQQ9SDH9iynD3qNwAEwzxUSlRNNs8kA
Additional context
No response