Skip to content

String.split in lib.d.ts should use a union, not overloads #12922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sandersn opened this issue Dec 14, 2016 · 3 comments
Closed

String.split in lib.d.ts should use a union, not overloads #12922

sandersn opened this issue Dec 14, 2016 · 3 comments
Assignees
Labels
Duplicate An existing issue was already created

Comments

@sandersn
Copy link
Member

TypeScript Version: master

Code

function split(notSure: string | RegExp) {
  return foo.split(notSure);
}

Expected behavior:

No error

Actual behavior:

Error: "Argument of type 'string | RegExp' is not assignable to parameter of type 'RegExp'."

@sandersn sandersn self-assigned this Dec 14, 2016
@Arnavion
Copy link
Contributor

Is this the decision for overloads in general, given that there are many issues about making overloads automatically work with union types instead? #5766 #12837 #12885

@mhegazy
Copy link
Contributor

mhegazy commented Dec 14, 2016

duplicate of #5766

@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 14, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 14, 2016

Is this the decision for overloads in general, given that there are many issues about making overloads automatically work with union types instead? #5766 #12837 #12885

The current recommendation is to keep the overload list as short as possible. #12885 tracks doing something about unifying them or flagging them as errors.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants