Skip to content

lib.d.ts Function.bind with this #28571

Description

Search Terms

Suggestion

i don't know what is better name for ITSOverwriteThisFunction

interfaceFunction2extendsFunction{bind<Textendsany,Fextends(...args: any[])=>any>(this: F,thisArg: T, ...argArray: any[]): ITSOverwriteThisFunction<T,F>;}exporttypeITSOverwriteThisFunction<Textendsany,Fextends(...args: any[])=>any>=(this: T, ...args: Parameters<F>)=>ReturnType<F>

Use Cases

  1. we can now let fn.bind, know who is this

problem: current typescript not support overload function, so this has limit

Examples

this examples looks so stupid, but i don't know how to make look better

exportinterfacet4extendsFunction2{(): string}exportdeclarelett5: t4exportlett6=t5.bind([]asstring[])t6=function(){this.includes('')// => this is string[]return''}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnactionableThere isn't something we can do with this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions