A value is cast to unknown or any and then to another type, bypassing the check
What it finds
value as unknown as Config, <Config>(<any>value): asserting first to unknown or any and then to the wanted type forces any value into any type, which the compiler would otherwise reject as an assertion between unrelated types. The second type is then trusted without any check.
Test doubles and code at the edges of untyped libraries do this on purpose, which is why the rule is strict.
From the rule's source, cast_through_unknown.rs.
interface Config { port: number;}function load(raw: string) { const a = raw as unknown as Config;tx0 reports: asserting through unknown forces the value into a type const b = <Config>(<any>raw);tx0 reports: asserting through any forces the value into a type const c = JSON.parse(raw) as Config; return [a, b, c];} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:cast-through-unknown" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:cast-through-unknown] reason="..."tx0 explain tx0/ts:cast-through-unknown shows the same in the terminal. Found a false positive? Report it.