domains / app-frameworks / chalk/chalk
TypeScript declaration conventions
When writing or updating `.d.ts` files, follow idiomatic TypeScript conventions to keep type declarations concise and consistent: - Avoid duplicating type definitions or their documentation. If a type already exists (locally or in an external package), re-export it instead of redefining it.
When writing or updating .d.ts files, follow idiomatic TypeScript conventions to keep type declarations concise and consistent:
- Avoid duplicating type definitions or their documentation. If a type already exists (locally or in an external package), re-export it instead of redefining it.
- Prefer explicit re-exports from the source module (e.g.,
export { ColorInfo, ColorSupport, ColorSupportLevel } from 'supports-color';) rather than inlining or copying type bodies. Group these re-exports together, typically at the bottom of the file. - Mark array-typed exports as
readonlywhen the underlying value is not meant to be mutated, e.g.export const modifiers: readonly Modifiers[];. - Use method shorthand syntax for interface members instead of arrow-function-typed properties, e.g. prefer:
interface Chalk { rgb(r: number, g: number, b: number): Chalk; }over
interface Chalk { rgb: (r: number, g: number, b: number) => Chalk; }
Following these conventions reduces duplication, keeps declaration files easier to maintain, and aligns with common TypeScript style used across the ecosystem.</description>