Skip to content

Typescript named type aliases to clarify the meaning of the variable

Notifications You must be signed in to change notification settings

dilame/claritype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

It's not always clear what does number or string type mean.

Let's imagine you are describing setTimeout

declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

In't not clear what number to pass in timeout. Let's refactor it

type Milliseconds = number;
declare function setTimeout(handler: TimerHandler, timeout?: Milliseconds, ...arguments: any[]): number;

Now it's much more clear, and user will see hints when typing this function in IDE.

So this library is just a set of such aliases. For now it contains

export type Milliseconds = number;
export type Seconds = number;
export type Minutes = number;
export type Hours = number;
export type Days = number;
export type Months = number;
export type Years = number;
export type Centuries = number;

So use it to clarify your inputs!

About

Typescript named type aliases to clarify the meaning of the variable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published