Skip to content
This repository was archived by the owner on Jun 2, 2019. It is now read-only.

Latest commit

 

History

History
71 lines (40 loc) · 1.68 KB

types.md

File metadata and controls

71 lines (40 loc) · 1.68 KB

Schema2ts internal express of type

Code tells anything, then intellisense will tell you the rest.

If you get confused, fell free to open an issue, then I will add that part to this document.

About Types. and Typescript.

Types. means type in schema2ts

Typescript. means type provided by Typescript package

Categories of Types

Literal Type

  • boolean (true, false)
  • number (-1, 0.5, 100, ...)
  • string ('Hello', 'World', ...)

Falsy Type

  • null
  • undefined

Typescript Falsy Type

  • any
  • void

Complex Type

  • array (Type[])
  • object (with type definition by an interface of course)

Constructed Type

  • or (TypeA | TypeB)
  • and (TypeA & TypeB)
  • tuple ([TypeA, TypeB])

Typescript Type

  • enum
  • type reference

Shared methods

toTypescript(): Typescript.TypeNode

This method return the Typescript TypeNode of it self.

For example, Types.Literal(true) express a boolean type, this method gives you a boolean TypeNode.

Then, Types.EnumOf(name, members...) express an enum, this method gives you the name, not declaration.

reduce(keepPrecise?: boolean): Types.Type

This method make type more clear.

For example, Types.And([ TypeA, TypeA ]).reduce() (which express TypeA & TypeA) will give you TypeA

getDeclaration(): Typescript.Declaration[]

This method gives you all type declaration you need to add to the output file, otherwise, result of .toTypescript() will not pass type checking.

addJSDoc(jsdoc: string | string[]): void

This method add JSDoc to the type.

Important!: But JSDoc maybe not emit in some types!