GithubHelp home page GithubHelp logo

etype's Introduction

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
AnyObject Represent to any object / Record<string | number | symbol, any>
OmitValueType Select the value type from T to be an attribute of V, and combine these attributes interface A {a: string; b: boolean; c: number; d: number}, OmitValueType<A, number> => {a: string; b: boolean;} /
PickValue Select the value type from T to be an attribute of V, and combine these attributes interface A {a: string; b: boolean; c: number; d: number},PickValue<A, number> => 'c'|'d' /
PartialKey Remove some properties from T interface A {a: string; b: boolean; c: 'f'|'m';},PartialKey<A, 'a'|'b'> => {c: 'f'|'m';} /

Suggestions and pull requests are welcome.

Reference

etype's People

Contributors

daolou avatar xcatliu avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.