GithubHelp home page GithubHelp logo

better-global-types's Introduction

@dfoverdx/better-global-types

Some augmentations of global methods that could be better. I'll update these as I think of them.

This package has a peer requirement of typescript@>=4.1.0 since it uses template literal types.

Installation

# npm
npm i -D @dfoverdx/better-global-types

# yarn
yarn add -D @dfoverdx/better-global-types

List of current augmentations

ObjectConstructor

Object.keys()

Return type now infers the actual keys of the object passed in. When an array is passed in, knows only to return numeric keys (as strings) and any extra properties you may have attached to it--ones not on the array prototype. It knows not to include symbols.

Known issues
  • Since TS currently has no way to infer an object's constructor, the type returned will include any prototype members as possible keys excluding those of Object.prototype and Array.prototype.

Object.entries()

Return type now infers the types of the key-value pairs of the object passed in, rather than [string, T[keyof T]]. Like Object.keys(), it handles array properly. It knows not to include tuples for symbol properties.

Known issues
  • Since TS currently has no way to infer an object's constructor, the type returned will include key-value pairs of any prototype members as possible keys excluding those of Object.prototype and Array.prototype.

Object.fromEntries()

Return type now correctly infers the shape of the object.

better-global-types's People

Contributors

dfoverdx avatar

Watchers

 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.