Git Product home page Git Product logo

proto-typescript's Introduction

proto-typescript

Utility types and implementations based on JavaScript prototypes. I plan to share the features that are officially available from 2.0.0.

TypedClass

prototype methods

new TypedArray([1, 2, 3] as const).unshift(4 as const); // TypedArray<[4, 1, 2, 3]>
new TypedArray([1, 2, 3] as const).join(','); // TypedString<'1,2,3'>

The return result of 'TypeClass' returns one of the instances of TypeClass again. Therefore, those who know the grammar of JavaScript can use it immediately.

refined methods

/**
 * error case
 */
new TypedArray<'1-3'>([1, 2, 3]).refine([1, 2, 3] as const).join('-');
new TypedArray<'1-3'>([]).refine([1, 2, 3] as const).join('-');
new TypedArray<'1-3'>().refine([1, 2, 3, 4] as const).join('-');
new TypedArray<'1-3'>().refine([0, 1, 2, 3] as const).join('-');

/**
 * right case
 */
new TypedArray<'1-3'>().refine([2, 3] as const).join('-');

TypedArray, TypedNumber has the refine method, which serves to further narrow down the generic type received as a factor. This helps reduce developer mistakes, but it should be careful because it cannot guarantee actual runtime behavior.

In the future, improvements will be made at the type level.

toPrimitive method

new TypedString('abcdef').toPrimitive(); // 'abcdef'

You can change it to the primitive type of JavaScript.

const arr = [...new TypedArray([1, 2, 3, 4, 5] as const)]; // (1 | 2 | 3 | 4 | 5)[]

Iterable/Iterator is supported.

proto-typescript's People

Contributors

kakasoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

proto-typescript's Issues

Multiple types related to numbers.

요청사항

특정한 형태의 숫자를 타입으로 제한하고 싶습니다.

  • 특정 형태의 숫자양식을 제한할 수 있는 타입
    • 예) 정수, 자연수, 음수, 실수(소수점 자리수까지 선택가능하면 best)
  • 숫자 범위 지정
    • 예) 0 ~ 1 사이의 숫자만 선택가능한 타입

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.