Closed shimikano closed 3 years ago
Same with something like this:
export enum ErrorType {
NoLobby,
FailCreate,
BadPassword,
Rejected
}
export enum SocketState {
NotConnected,
Connected
}
type ErrorMap = {
readonly [key in ErrorType]?: string
};
const lobbyError = useCallback((message: LobbyErrorMessage) => {
updateErrorMap(draft => {
switch (message.subType) {
case EngageMessageType.CreateLobby:
draft[ErrorType.FailCreate] = "Lobby code rejected (duplicate or bad word): " + message.lobbyCode;
break;
case EngageMessageType.LobbyJoined:
draft[ErrorType.NoLobby] = "No lobby found with code: " + message.lobbyCode;
break;
case EngageMessageType.GetLobbyInfo:
draft[ErrorType.BadPassword] = "The password entered does not match.";
break;
}
});
},[updateErrorMap]);
The error is TS2540: Cannot assign to '0' because it is a read-only property.
This compiled fine in the last version.
Addressed OP in 0.5.2. Thanks for reporting!
@pip8786 didn't check your case. Please check against 0.5.2 and if it doesn't work best open a fresh issue including a CodeSandbox reproduction.
Reproduced here:
https://codesandbox.io/s/use-immer-typing-vp697?file=/src/App.tsx
The example compiles without errors using use-immer-0.4.2.