@@ -120,6 +120,7 @@ Type assertions make the code brittle against changes. While TypeScript will thr
120
120
##### To prevent or fix ` any ` usage
121
121
122
122
Unsafe as type assertions may be , they are still categorically preferable to using ` any ` .
123
+
123
124
- With type assertions , we still get working intellisense, autocomplete, and other IDE features.
124
125
- Type assertions also provide an indication of the expected type as intended by the author.
125
126
- For type assertions to an incompatible shape, use `as unknown as` as a last resort rather than `any` or `as any`.
@@ -131,6 +132,7 @@ Unsafe as type assertions may be, they are still categorically preferable to usi
131
132
##### To type data objects whose shape and contents are determined at runtime
132
133
133
134
Preferably , this typing should be accompanied by schema validation performed with type guards and unit tests.
135
+
134
136
- e .g . The output of ` JSON.parse() ` or ` await response.json() ` for a known JSON input .
135
137
- e .g . The type of a JSON file.
136
138
@@ -139,6 +141,7 @@ Preferably, this typing should be accompanied by schema validation performed wit
139
141
##### In tests , for mocking or to exclude irrelevant but required properties from an input object
140
142
141
143
< ! -- TODO : Add examples -- >
144
+
142
145
It ' s recommended to provide accurate typing if there' s any chance that omitting properties affects the accuracy of the test .
143
146
144
147
Otherwise , only mocking the properties needed in the test improves readability by making the intention and scope of the mocking clear , not to mention being convenient to write .
0 commit comments