Skip to content

Commit 5bfa04b

Browse files
committed
docs: improve README examples, bump v0.1.1
- Replace Record<string, string> with Record<Route, string> to show satisfies key exhaustiveness checking - Show as const and as const satisfies as allowed patterns - Fix Bad example to demonstrate missing-field problem
1 parent 2e8f156 commit 5bfa04b

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,24 @@ This rule nudges code toward:
3838
## Examples
3939

4040
```typescript
41-
// Bad
42-
const canvas = document.getElementById("c") as HTMLCanvasElement;
43-
const name = <string> data.name;
44-
45-
// Good
46-
const canvas: HTMLCanvasElement | null = document.querySelector("canvas");
47-
const config = { mode: "dark" } satisfies AppConfig;
41+
// Bad — compiler won't catch missing fields
42+
const user = {} as { name: string; email: string };
43+
const el = <HTMLCanvasElement> document.getElementById("c");
44+
45+
// Good — type annotation catches missing fields at compile time
46+
const user: { name: string; email: string } = { name: "alice", email: "a@b.c" };
47+
48+
// Good — satisfies ensures all keys are covered (forget one → compile error)
49+
type Route = "home" | "about" | "contact";
50+
const paths = {
51+
home: "/",
52+
about: "/about",
53+
contact: "/contact",
54+
} satisfies Record<Route, string>;
55+
56+
// Good — as const and as const satisfies are always allowed
57+
const ROLES = ["admin", "user"] as const;
58+
const config = { debug: false } as const satisfies { debug: boolean };
4859
```
4960

5061
## Ignoring a report

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hiro5409/deno-no-type-assertion-lint",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"license": "MIT",
55
"exports": "./mod.ts",
66
"publish": {

0 commit comments

Comments
 (0)