@density/lib-common-types
v1.1.1
Published
Common types and enums
Downloads
2
Keywords
Readme
lib-common-types
Common types and enums used by Density TypeScript projects.
Setup
Common types can be used in any TypeScript file with a standard import:
import { DayOfWeek } from '@density/lib-common-types';
Recommended ambient/global types are also provided in the global.d.ts
file. We provide three special Any<T>
types which should be used in place of explicit any
declarations (as the normal rule). Implicit any
should be disallowed by the typescript compiler if possible. To use the global Any<T>
types, add this triple-slash directive to an index file in your project:
/// <reference path="../node_modules/@density/lib-common-types/global.d.ts" />
The three generic parameters compatible with this Any<T>
type are as follows:
// When you don't have time to think about types, or intend to come back before review, use Any<InAHurry>
const foo: Any<InAHurry> = 123;
// When you intend to define a type before shipping, or would like the reviewer to do so, use Any<FixInReview>
const bar: Any<FixInReview> = 123;
// All above types that are not replaced in review should be converted to Any<FixInRefactor>
const baz: Any<FixInRefactor> = 123;
// The true `any` type should only be used in exceptional cases, and is discouraged
// This ejects from type analysis indefinitely and leaves a mini-booby-trap that we intend to live with
const quux: any = someLibrary().unpredictableFactoryWhatnot();