Skip to content

Commit 40af6c2

Browse files
committed
refactor: update type safety guidelines
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent 7911243 commit 40af6c2

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ src/
182182
- Use `consola` for logging, not `console.log` (configured in `src/setupConsola.ts` — warn in prod, verbose in dev)
183183
- Type imports: `import type { ... }` for types only (`verbatimModuleSyntax: true`)
184184
- `satisfies` keyword for store module type checking
185+
- No double-cast type assertions (`as unknown as T`) — use a proper TypeScript type guard instead (`in`, `typeof`, `instanceof`, or a custom type predicate):
186+
187+
```typescript
188+
// Bad
189+
const x = value as unknown as { test: () => void }
190+
x?.test?.()
191+
192+
// Good
193+
if (value && 'test' in value && typeof value.test === 'function') {
194+
value.test()
195+
}
196+
```
185197

186198
## Git & Contribution Policy
187199

src/store/layout/getters.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export const getters = {
3131
}
3232
},
3333

34-
isEnabledInLayout: (state, getters) => (layout: string, id: string): boolean => {
35-
const configs = Object.values(getters.getLayout(layout) ?? {}).flat() as LayoutConfig[]
34+
isEnabledInLayout: (state, getters) => (name: string, id: string): boolean => {
35+
const layout: LayoutContainer | undefined = getters.getLayout(name)
36+
const configs = layout
37+
? Object.values(layout).flat()
38+
: []
3639

3740
return configs.find(configs => configs.id === id)?.enabled ?? false
3841
},

0 commit comments

Comments
 (0)