KScript ドキュメント
JA

言語

英語から自動翻訳されています。原文は英語です。

エラーコード

KS5020

strict なファイルで、チェッカーが型を証明できない値です。値を宣言する場所に型を書いてください。strict なファイルではエラーになり、修正するまでスクリプトは実行されません:

<strict />

<let name="names" value="[]" /> <!-- error: write the item type, such as $names: string[] = [] -->
<let name="found" value="null" /> <!-- error: write its type: $found: string? = null -->
<let name="data" type="any" value="'{&quot;n&quot;: 1}'->convert(from: json)" />
<let name="n" value="$data.n" /> <!-- error: the checker can't tell what $n holds; write $n: int = $data.n -->
strict

$names = []                   // error: write the item type, such as $names: string[] = []
$found = null                 // error: write its type: $found: string? = null
$data: any = '{"n": 1}'->convert(from: json)
$n = $data.n                  // error: the checker can't tell what $n holds; write $n: int = $data.n

同じコードで、異なる型の値が代入される変数、型を取る手がかりのない lambda パラメーター(fn(n: number) => ... と書く)、結果を推論できない関数(fn first(items: list): string と書く)、型もデフォルト値もないフィールドも報告されます。