Kiro steering for strict TypeScript: compiler options beyond strict, discriminated unions, branded IDs, unknown with narrowing, and no any.
.kiro/steering/kiro-typescript-strict-mode.md. Downloaded files need to be placed in that repository path.---
inclusion: fileMatch
fileMatchPattern: "**/*"
---
Apply these rules to TypeScript code in this workspace.
## Strict configuration
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true
}
}
```
- `strict` is on by default since TypeScript 6.0; keep it explicit. `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes` are not part of `strict`; keep them on in this workspace and fix the errors they report.
- Run `tsc --noEmit` as part of every task's verification.
## Type patterns
```ts
// Discriminated unions
type Result<T> =
| { success: true; data: T }
| { success: false; error: string };
function unwrap<T>(result: Result<T>): T {
if (result.success) return result.data;
throw new Error(result.error);
}
// Branded types, created in one function
type UserId = string & { readonly __brand: 'UserId' };
function toUserId(id: string): UserId {
if (!/^usr_[a-z0-9]+$/.test(id)) throw new Error(`Invalid user id: ${id}`);
return id as UserId;
}
// unknown + narrowing for external data
function readPort(env: Record<string, string | undefined>): number {
const raw = env.PORT;
const port = raw === undefined ? 3000 : Number(raw);
if (!Number.isInteger(port) || port <= 0) throw new Error(`Invalid PORT: ${raw}`);
return port;
}
```
## Practices
- Never use `any`; use `unknown` for values of unknown shape and narrow them.
- Prefer interfaces for object shapes and type aliases for unions (or one style consistently).
- Use `as const` for literal values and `satisfies` to check objects against a type without widening.
- With `noUncheckedIndexedAccess`, handle `undefined` from `array[i]` and record lookups instead of adding `!`.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for TypeScript project setup covering strict tsconfig flags and their effects, type-only imports, module hygiene and TSDoc for public APIs.
Kiro
general
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Kiro task implements user lookup; the generated code uses `any` for env parsing and `users[0]!` to silence noUncheckedIndexedAccess.
Implement getFirstActiveUser(users) and config parsing for PORT following the TypeScript steering file.
Functions that return User | undefined (or a Result) instead of using !, a toUserId constructor that validates the format, readPort that narrows the env string and rejects invalid values, and a note that tsc --noEmit passes.
Kiro, built and operated by AWS, uses steering files: Markdown documents in .kiro/steering/ that give the agent persistent project knowledge. Front matter controls when each file is included: always, when matching files are in context, manually by #name, or automatically by description. Kiro also includes AGENTS.md files.
.kiro/steering/kiro-typescript-strict-mode.mdStarting point, not a tested configuration for your repository. Included when files matching fileMatchPattern are in context. Review the instructions, adapt the file paths and run your project's existing checks.
---
inclusion: fileMatch
fileMatchPattern: "**/*"
---
Apply these rules to TypeScript code in this workspace.
## Strict configuration
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true
}
}
```
- `strict` is on by default since TypeScript 6.0; keep it explicit. `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes` are not part of `strict`; keep them on in this workspace and fix the errors they report.
- Run `tsc --noEmit` as part of every task's verification.
## Type patterns
```ts
// Discriminated unions
type Result<T> =
| { success: true; data: T }
| { success: false; error: string };
function unwrap<T>(result: Result<T>): T {
if (result.success) return result.data;
throw new Error(result.error);
}
// Branded types, created in one function
type UserId = string & { readonly __brand: 'UserId' };
function toUserId(id: string): UserId {
if (!/^usr_[a-z0-9]+$/.test(id)) throw new Error(`Invalid user id: ${id}`);
return id as UserId;
}
// unknown + narrowing for external data
function readPort(env: Record<string, string | undefined>): number {
const raw = env.PORT;
const port = raw === undefined ? 3000 : Number(raw);
if (!Number.isInteger(port) || port <= 0) throw new Error(`Invalid PORT: ${raw}`);
return port;
}
```
## Practices
- Never use `any`; use `unknown` for values of unknown shape and narrow them.
- Prefer interfaces for object shapes and type aliases for unions (or one style consistently).
- Use `as const` for literal values and `satisfies` to check objects against a type without widening.
- With `noUncheckedIndexedAccess`, handle `undefined` from `array[i]` and record lookups instead of adding `!`.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Front matter must be at the very beginning of a steering file to be recognized. Kiro supports AGENTS.md. According to the steering docs, AGENTS.md files do not support inclusion modes and are always included, so keep scoped guidance in .kiro/steering/ files instead.
Documentation checked 2026-11-05: Kiro docs: SteeringKiro home page
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for TypeScript project setup covering strict tsconfig flags and their effects, type-only imports, module hygiene and TSDoc for public APIs.