SKY-T103 · Quality, structure and performance
Suspicious chained type assertion
A type assertion (value as User) tells the TypeScript compiler to trust you about a value's type; it checks nothing at run time. Chaining two assertions through unknown or any (value as unknown as User) forces a type the compiler would otherwise reject. SKY-T103 reports such a chain when it ends in a precise type.
- Languages
- TypeScript
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
The compiler stops checking, so if the value does not have that shape the error appears later and somewhere else: user.isAdmin is undefined, the admin check quietly fails, or a missing field crashes a page far from the line that caused it.
What Skylos flags
type User = { id: string; email: string; isAdmin: boolean }; export function currentUser(session: { user: object }): User { return session.user as unknown as User;}What Skylos leaves alone
type User = { id: string; email: string; isAdmin: boolean }; function isUser(value: unknown): value is User { const v = value as Record<string, unknown>; return ( typeof v.id === "string" && typeof v.email === "string" && typeof v.isAdmin === "boolean" );} export function currentUser(session: { user: object }): User { if (!isUser(session.user)) { throw new Error("session has no valid user"); } return session.user;}Why Skylos leaves it alone
The only assertion is a single step to Record<string, unknown>, a type that still says "unknown", inside a type guard that checks every field at run time. Skylos reports only a chain whose last type is precise.
How Skylos decides
- Runs with
--qualityon.ts,.tsx,.mtsand.ctsfiles. Declaration files (.d.ts) and generated files (underbuild,dist,generatedorvendorfolders,*.gen.tsor*.generated.tsnames, or with a generated-code header) are skipped, and so is code inside a part of the file that does not parse. - Finds a type assertion, written
x as Tor<T>x, whose operand is itself an assertion, looking through parentheses,await,!andsatisfies. - The inner assertion must be to a bridge type:
unknown,any,objector{}. - The outer type must be precise: not
as const, and with noany,unknown,objector{}anywhere inside it.x as unknown as Record<string, unknown>is therefore not reported. - Reports MEDIUM on the line where the outer assertion starts.
How to fix it
Check the value at run time with a type guard (or a schema library such as Zod) and let the compiler narrow it, instead of asserting it.
type User = { id: string; email: string; isAdmin: boolean }; Added: function isUser(value: unknown): value is User {Added: const v = value as Record<string, unknown>;Added: return (Added: typeof v.id === "string" &&Added: typeof v.email === "string" &&Added: typeof v.isAdmin === "boolean"Added: );Added: }Added: export function currentUser(session: { user: object }): User {Removed: return session.user as unknown as User;Added: if (!isUser(session.user)) {Added: throw new Error("session has no valid user");Added: }Added: return session.user;}When it can be wrong
- A chain is sometimes the only way to bridge two library types that describe the same object, for example two versions of a generated client. It is still reported.
- A single assertion such as
data as Userhides the same problem but is not reported by this rule.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
On the reported line:
TypeScript return session.user as unknown as User; // skylos: ignore[SKY-T103] auth checked it[tool.skylos] ignore = ["SKY-T103"]inpyproject.tomlturns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.