Skip to content
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

TS: Prefer union arguments to overloads for simple cases #19403

Merged
merged 1 commit into from May 20, 2020

Conversation

willstott101
Copy link
Contributor

This works around microsoft/TypeScript#14107

In my typescript project I accept config for colors as color: string | number but using that with threejs can be a fiddle in some cases:

  Overload 2 of 3, '(color: number): Color', gave the following error.
    Argument of type 'string | number' is not assignable to parameter of type 'number'.
      Type 'string' is not assignable to type 'number'.
  Overload 3 of 3, '(color: string): Color', gave the following error.
    Argument of type 'string | number' is not assignable to parameter of type 'string'.

I searched the codebase for overloads using ( +)(\w+)\(.+\n\1\2\( and it looks like Color is pretty much the only unnecessary use of overloads so have fixed all those which I found.

I cannot see any typescript tests besides lint so I have't tried to add any.

@mrdoob mrdoob added this to the r117 milestone May 20, 2020
@mrdoob
Copy link
Owner

mrdoob commented May 20, 2020

That'll teach me to not do this kind of things in the APIs 😅

@mrdoob mrdoob merged commit b709e02 into mrdoob:dev May 20, 2020
@mrdoob
Copy link
Owner

mrdoob commented May 20, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants