3 ms·
Generally, try the following steps: - turn off strict flags, turn them on again after everything compiles in non strict mode - ensure you have the correct typi
by amoerie 7y ago
Generally, try the following steps:
- turn off strict flags, turn them on again after everything compiles in non strict mode
- ensure you have the correct typings for the libraries you're using. Some libraries include them, others require a @typings/xyz dependency. (E.g. React and ReactDOM)
- try to hunt down the root errors. Much like C# or Java, one error can lead to hundreds of compilation errors down the line, but fixing the first root error can also make all of them go away in one fell swoop.
- try to keep things simple and non dynamic. Typescript is very flexible and powerful, but think twice before you use crazy constructs.
- enable emitOnError. It will allow you to test while you refactor, even though typescript complains.
- ask yourself: if it works and typescript does not compile, is it because typescript can't understand or is it because typescript is seeing possible issues you've not taken into account?
- don't think of typescript as something to get around of. Think of it as a helping hand that will guide you in your daily work and prevent a whole swath of runtime errors, but it needs to be fed with information about your data structures and libraries to work properly.
- seanmcdirmid 7y agoTypescript is really unlike C# or Java though, error cascading is a much much bigger issue in a structural type system than a nominal one, where the x method not implemented by class C will trigger whenever you try to call the x method (in a nominal type system you just get the error once, the typescript team could probably do a better job with this by investing some resources into the problem).