type-safety
/type-safety
Pomaga modelować dane tak, aby niedozwolone stany się nie kompilowały, i wykorzystać ścisły kompilator do wzmacniania luźno otypowanych modułów.
- Autor
- Amey-Thakur ↗
- Repozytorium
- AI-SKILLS ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 05.09.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 05.09.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga modelować dane tak, aby niedozwolone stany się nie kompilowały, i wykorzystać ścisły kompilator do wzmacniania luźno otypowanych modułów.
Oryginalny opis (EN)
Model data so illegal states will not compile, then turn the checker to strict and let it prove correctness for free. Use when designing types, modeling state machines, or hardening a loosely typed module.
Jak działa
- Method
- Checks
- Boundaries
Podgląd SKILL.md
---
name: type-safety
description: Model data so illegal states will not compile, then turn the checker to strict and let it prove correctness for free. Use when designing types, modeling state machines, or hardening a loosely typed module.
---
# Type safety
A type is a proof the compiler rechecks for free on every build, but only
about the things you let it see. Model with loose types (everything a
string, every field optional, states tracked by scattered flags) and the
compiler cannot help; model tightly and whole categories of bug stop
compiling.
## Method
1. **Make illegal states unrepresentable.** Replace a `status: string` plus
a nullable `error` with a tagged union: `{ kind: 'loading' } | { kind:
'ok', data: T } | { kind: 'error', message: string }`. Now "ok with an
error message" cannot be constructed, so no code has to guard against
it.
2. **Parse, do not validate, at the edge.** Turn input into a precise type
once (`Email`, `UserId`, `NonEmptyList`) with zod, io-ts, or pydantic,
then pass that type inward. A function taking `Email` never re-checks the
`@`, because the type already carries the proof.
3. **Wrap primitives that mean different things.** A `UserId` and an
`OrderId` that are both bare `string` will get swapped eventually.
Branded types, newtypes, or `NewType` in Python make the swap a compile
error at no runtime cost.
4. **Keep required fields required.** Make a field optional only when
absence is a real, handled case. Every `?` you add is a branch every
caller inherits, so keep the mandatory fields mandatory and let the type
document what must exist.
5. **Turn the checker to strict.** `strict: true` in tsconfig, mypy
`--strict`, Kotlin explicit-API mode, the relevant `-Werror` analyses.
Half-on type checking passes files a full pass would reject, which is
worse than knowing they are unsound.
6. **Make exhaustiveness a compile error.** Switch on a union with a
`never` default (TypeScript) or a sealed `when` (Kotlin) so adding a
variant fails the build at every site that does not yet handle it. The
compiler becomes your checklist for the change.
## Checks
- Can you construct a value that is in two contradictory states at once? If
so, tighten the type.
- Does adding a new enum case break the build at every site that must
change?
- Are `UserId` and `OrderId` distinguishable to the compiler, or both just
`string`?
## Boundaries
Dynamic languages without gradual typing, and seams with untyped systems
(raw JSON, FFI, reflection), cap how much the compiler can prove: validate
at those seams instead. Type modeling has a cost, and past a point the
ceremony outweighs the bugs prevented, so stop tightening when the next
constraint costs more than the mistake it would block.
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · Amey-Thakur/AI-SKILLS | 90 | MIT |
| jacob-balslev/skill-graph | 100 | Apache-2.0 |
Migawka bazy z 28.10.2026 · wersja paczki 1d4ecc27b2a8 (skrót SHA-256 całej paczki)
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100typescript-type-safety
Modeluje stany typami tak, by niepoprawne kombinacje nie przechodziły kompilacji, a dane wejściowe sprawdza schematem. - 90type-driven
Pomaga modelować domenę, maszyny stanów i API tak, aby niepoprawne stany były niemożliwe do wyrażenia, oraz parsować dane zamiast je tylko walidować. - 100parse-dont-validate
Stosuje zasadę projektowania opartą na typach: zamienia dane niestrukturalne w typy strukturalne na granicach systemu, tak by stany niedozwolone były niereprezentowalne, przy walidacji, typach danych i obsłudze błędów. - 100typescript-type-safety
Usuwa dziury w typach TypeScript: zastępuje any interfejsami, guardami typów i augmentacją modułów. - 100reviewing-module-design
Przegląda strukturę klas i modułów, interfejsy oraz modelowanie danych, szukając stanów, które nie powinny dać się zapisać. - 100typescript-pro
Projektuje architekturę typów dla NestJS, Angular i serwerów MCP: współdzielone kontrakty, dekoratory i konfigurację.