Socket
Socket
Sign inDemoInstall

bind.ts

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bind.ts

Function.prototype.bind with typings for TypeScript


Version published
Weekly downloads
17
decreased by-39.29%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

bind.ts

Function.prototype.bind with typings for TypeScript

npm version Node.js Version Support build status dependency status License

Function#bind is untyped in TypeScript (in v2.3 at least, cf: #212). TypeScript always returns any for bind().

function foo(a: number, b: number): string {
    return `${this.msg}: ${a + b}`;
}
// bar is `any`!
const bar = foo.bind({msg: 'hello'}, 10);
// ok
bar(20); // 'hello: 30'
// should be a type error, but actually allowed...
bar('anything');

bind.ts is a workaround for this issue.

import bind from 'bind.ts';

// bar is `(b: number) => string`
const bar = bind(foo, {msg: 'hello'}, 10);
// ok
bar(20); // 'hello: 30'
// error!
bar('anything');

Limitation

The maximum number of arguments of the function is 5.

License

MIT License: Teppei Sato <teppeis@gmail.com>

FAQs

Last updated on 30 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc