Better motivate no-class rule #314
Replies: 4 comments
-
If you'd like to make a PR for this change, we can add it. |
Beta Was this translation helpful? Give feedback.
-
Quick question about the |
Beta Was this translation helpful? Give feedback.
-
@crqra Errors can be anything, they don't have to be an instance of const error = {
type: "general error",
message: "Something went wrong."
} Though in practice, it is usually best to just use If you want to take it a step further, you can blackbox the classes. |
Beta Was this translation helpful? Give feedback.
-
@RebeccaStevens What I was doing was something similar, using functions like: const buildSomeError = (some: string) => Error(`there was some error: ${some}`) Having all classes in a sub-dir or single file and just export the functions looks much better because you can implement the actual "type" of error, like Thank you for the concise reply, was very helpful! |
Beta Was this translation helpful? Give feedback.
-
It might be useful to give examples of where classes lead to unsoundness to help motivate the no-class rule.
Here's an example derived from https://medium.com/free-code-camp/typescript-and-its-types-f509d799947d that still applies to TS 3.9:
Beta Was this translation helpful? Give feedback.
All reactions