javascript-practices
JS/TS conventions for syntax, modules, and types. Use when writing or reviewing JavaScript/TypeScript code.
javascript
practices
SKILL.mddata/javascript-practices
GitHubJavaScript/TypeScript Practices
How TypeScript packages are written in this codebase: modules, runtime access, types and tests. Node runs the TypeScript source directly, and libraries reach the runtime through the cross-runtime layer. React and browser UI are in frontend-practices.
Always
- Always import as a namespace (
import * as semver from "semver"), in code, tests, JSDoc@exampleblocks and READMEs alike; the only exceptions areruntimefrom@eserstack/standards/cross-runtime, type-only imports and the default import of a JSON or CSS module - Import a package through its root, or in code and tests through a sub-path it
publishes in
exportswhen that keeps the module graph small; READMEs show the root, or/modfor a package whose.export is its CLI - Named exports on the declaration; no default exports except where a framework
loads a module's
default - Relative imports carry the
.tsextension; a package's entry ismod.ts; noexport * - File system, env, process and exec access goes through
runtime, neverprocess.*,node:fsor another runtime's globals in library code - Erasable syntax only: no enums, namespaces or parameter properties; exported declarations carry explicit types
- Only booleans use implicit checks; defaults use
??, never|| - Where this codebase runs
validate-code-conventions, it enforces the import,||andexport *rules on new code against a baseline that only ever shrinks nullfor absent values you define;instanceoffor object typesreturn awaitin async functions; every promise is awaited or owned- Tests are co-located
*.test.tsfiles onnode:test, with assertions and mocks from@eserstack/test-kit - oxfmt, oxlint and
tsc --noEmitenforce formatting, the basics and the types; run them instead of hand-checking
References
| File | Read when |
|---|---|
| modules.md | Adding imports or exports, creating a module or mod.ts |
| syntax-and-types.md | Runtime APIs, paths, syntax, export types, checks, async returns |
| testing.md | Writing or running TypeScript tests or benches |