File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ function handler(event: Event) {
9797}
9898```
9999
100- あなたがその型を依然として必要とするなら、二重アサーションを使うことができますが、最初にすべての型と互換性のある` any ` をアサートするので、コンパイラはもう文句を言うことはありません:
100+ あなたがその型を依然として必要とするなら、二重アサーションを使うことができますが、最初にすべての型と互換性のある` unknown ` (または ` any ` ) をアサートするので、コンパイラはもう文句を言うことはありません:
101101
102102``` ts
103103function handler(event : Event ) {
@@ -107,3 +107,8 @@ function handler(event: Event) {
107107
108108#### TypeScriptが単一のアサーションが不十分と判断する方法
109109基本的に、` S ` が` T ` のサブタイプであるか ` T ` が` S ` のサブタイプである場合、` S ` から` T ` へのアサーションは成功します。これは、タイプアサーションを行う際に特別な安全性を提供するためです。完全に任意の型アサーションは非常に安全でない可能性があります。そして、安全でない状態にするために、あなたは` any ` を使用する必要があります。
110+
111+ #### ` as any as ` vs ` as unknown as `
112+ 両方とも Typescript からすると同じくらい安全ではないです。お好きな方をお使いください。考慮する点としては:
113+ - Linter は ` unknown ` を好む (` no-explicit-any ` ルールを設定している場合)
114+ - ` any ` は ` unknown ` よりタイピングする文字数が少ない
You can’t perform that action at this time.
0 commit comments