ety
etype
npm i etype
ety

etype

Extra types for TypeScript

by xcatliu

0.1.3 (see all)License:MITTypeScript:Not Found
npm i etype
Readme

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

TypeDescriptionExampleReal Type
int32-bit signed two's complement integer, which has a minimum value of -2^31 and a maximum value of 2^31-10, 1, 2, -1, -2147483648, 2147483647number
floatSingle-precision 32-bit IEEE 754 floating point0.1, -1.23number
IntStringInt-like-string"100", "-1"string
FloatStringFloat-like-string"1.00", "-0.1"string
DateStringDate-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
JSONStringJSON-string which can be converted to json object by JSON.parse(foo)"{\"hello\":\"world\"}"string
BooleanIntUse int to represent a boolean0, 10 \| 1
AnyFunctionRepresent 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

No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate