All Projects → teppeis → bind.ts

teppeis / bind.ts

Licence: other
Function.prototype.bind with typings for TypeScript

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to bind.ts

skinner
Skin export / import tools for Autodesk Maya
Stars: ✭ 68 (+353.33%)
Mutual labels:  bind
bind-to-tinydns
Convert zone files from the BIND DNS server into configs for djbdns's tinydns
Stars: ✭ 18 (+20%)
Mutual labels:  bind
DNS-Parser
This library parses BIND zone files and outputs DNS objects.
Stars: ✭ 16 (+6.67%)
Mutual labels:  bind
dnstap-receiver
Dnstap streams receiver in Python
Stars: ✭ 33 (+120%)
Mutual labels:  bind
NetworkAdapterSelector
A simple solution to let you force bind a program to a specific network adapter
Stars: ✭ 168 (+1020%)
Mutual labels:  bind
ObservableComputations
Cross-platform .NET library for computations whose arguments and results are objects that implement INotifyPropertyChanged and INotifyCollectionChanged (ObservableCollection) interfaces.
Stars: ✭ 94 (+526.67%)
Mutual labels:  bind
zonemanager
Central DNS/DHCP database with replication to Amazon Route53, BIND, MikroTik routers and other services.
Stars: ✭ 29 (+93.33%)
Mutual labels:  bind
mercator
Automatic typeclass-based abstraction over monad-like types
Stars: ✭ 54 (+260%)
Mutual labels:  bind
laravel-route-model-autobinding
THIS PACKAGE HAS BEEN DEPRECATED — Automatically bind Eloquent models as route segment variables.
Stars: ✭ 14 (-6.67%)
Mutual labels:  bind
ansible-role-dns
Install and configure dns on your system.
Stars: ✭ 39 (+160%)
Mutual labels:  bind
RCE-python-oneliner-payload
Python bind shell single line code for both Unix and Windows, used to find and exploit RCE (ImageMagick, Ghostscript, ...)
Stars: ✭ 23 (+53.33%)
Mutual labels:  bind

DEPRECATED: Use --strictBindCallApply instead since TypeScript 3.2

Finally TypeScript 3.2 officially supports this feature!!!

See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-2.html#strictbindcallapply


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 v3.0 at least, cf: #212). It always returns any.

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');

Note: TypeScript v3.0 introduces generic rest parameters. It's helpful but cannot solve this issue completely and the type definition of Function#bind in TypeScript core is not changed.

Requirement

bind.ts v2 requires TypeScript v3.0+. For TypeScript v2.x, use bind.ts v1.

Limitation

The maximum number of params of bind() is 5.

License

MIT License: Teppei Sato <[email protected]>

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].