Skip to content

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

Closed
@bluelovers

Description

@bluelovers

Search Terms

Suggestion

i don't know what is better name for ITSOverwriteThisFunction

interface Function2 extends Function
{
	bind<T extends any, F extends (...args: any[]) => any>(this: F, thisArg: T, ...argArray: any[]): ITSOverwriteThisFunction<T, F>;
}

export type ITSOverwriteThisFunction<T extends any, F extends (...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

export interface t4 extends Function2
{
	(): string
}

export declare let t5: t4

export let t6 = t5.bind([] as string[])

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