etype
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

etype

npm deno

Extra types for TypeScript.

Most of the time we can be sure that the type of a variable is int. However, there is no int type in TypeScript, so we have to write code with comment like this:

/** age is int */
const age: number;

Is there a better way? Of course! We can define a type alias like this:

type int = number;

const age: int;

In this way, although we can not limit the type of value of age, it makes the code more readable.

Based on this idea, we provides some extra types for TypeScript.

Usage

Install:

npm install etype --save-dev

Import in your ts files:

import type { int } from 'etype';

const age: int;

Import in Deno:

import type { int } from 'https://deno.land/x/etype/mod.ts';

const age: int;

Types

Type Description Example Real Type
int 32-bit signed two's complement integer, which has a minimum value of -2^31 and a maximum value of 2^31-1 0, 1, 2, -1, -2147483648, 2147483647 number
float Single-precision 32-bit IEEE 754 floating point 0.1, -1.23 number
IntString Int-like-string "100", "-1" string
FloatString Float-like-string "1.00", "-0.1" string
DateString Date-like-string which can be converted to Date object by new Date(foo) "Mon, 19 Oct 2020 13:09:21 GMT", "2020-09-10 17:28:35" string
JSONString JSON-string which can be converted to json object by JSON.parse(foo) "{\"hello\":\"world\"}" string
BooleanInt Use int to represent a boolean 0, 1 0 | 1
AnyFunction Represent to any function / (...args: any[]) => any

Contributing

  • Search issues before ask a question
  • For feature request, submit an issue before create a pull request
  • Run npm run build to compile index.ts
  • utility-types should be maintained in their repository

Reference

Readme

Keywords

none

Package Sidebar

Install

npm i etype

Weekly Downloads

4

Version

0.1.3

License

MIT

Unpacked Size

10.7 kB

Total Files

14

Last publish

Collaborators

  • xcatliu