Skip to content

Commit f52aa56

Browse files
authored
Update type-assertion.md
1 parent 707f7c4 commit f52aa56

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/types/type-assertion.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,9 @@ function handler(event: Event) {
108108

109109
#### How TypeScript determines if a single assertion is not enough
110110
Basically, the assertion from type `S` to `T` succeeds if either `S` is a subtype of `T` or `T` is a subtype of `S`. This is to provide extra safety when doing type assertions ... completely wild assertions can be very unsafe and you need to use `unknown` (or `any`) to be that unsafe.
111+
112+
#### `as any as` vs `as unknown as`
113+
Both are *equally unsafe* as far as TypeScript is concerned. Use what makes you happy. Considerations:
114+
115+
* Linters prefer `unknown` (with `no-explicit-any` rule)
116+
* `any` is less words to type than `unknown`

0 commit comments

Comments
 (0)