Zamiel
Zamiel
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Zamiel on 8/7/2023 in #questions
How to use readonly arrays with immer?
Consider the following short code snippet: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgESgQwGbwL5w1CEOAIlBAFMpiBuAKFuADsZKM0BjcuAWQE8BlGGhaJacOFHJoAJhEYAbXnBACArgCNBw8gC4eazUJZ1s9JiyhtO+-hq0iEYiVNkKlAZ0LlBUJgHM9dxhfRj86cUkZOUU4Twoff3c9SNcYoJC-AG0AXRN6DFVGdhhgOTg-chhkcjZVeRg+W0NtAAoASj1GuyMuRwjK1ShGUXFxOO9g-z1iDAgIYgAaJzGvBNCkuEyZucWSdTQqbKXxU1NaAqKSspUAJXJpVU4oADFC4tLGFqDtPVRMGAAPI0egA+NojODsORBZQGexcAC85Uq1Vq9S6zRY7XCsR6ADoVE14XAkYTuto8kA Immer seems to have a problem with readonly arrays, which doesn't make sense to me, because your state should always be immutable, which is the whole point of using immer in the first place. Before Immer version 7, this pattern worked fine, but in Immer 8+, it throws an error. How do I work around this problem or structure my code in the correct way?
2 replies
TTCTheo's Typesafe Cult
Created by Zamiel on 10/5/2022 in #questions
Alternative to TypeScript Classes
Currently, I'm refactoring TypeScript code into classes because I want to use extends for N features to inherit some base functionality. Previously, I had pockets of functions organized in separate files based on the type of functionality that they were providing. (foo.ts, bar.ts, baz.ts) I figured classes would be better to stay DRY, as it removes a lot of copy-paste boilerplate between every feature. (common variables + common functions) But I'm finding it really difficult to transition this structure into classes, because there are shared variables in a feature directory (variables.ts), and there is no partial keyword in TypeScript like there is in C#, so I have to stick thousands of lines of code in the same file (to avoid circular imports). As a result, I'm brainstorming ideas about how I could use normal objects to emulate classes, but it seems very messy. Are there any blogs that describe some patterns that might be useful here?
2 replies