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

Using && with spread operator causes "overridden" error if one of the types is "any" #39113

Closed
mastrzyz opened this issue Jun 17, 2020 · 10 comments · Fixed by #39529
Closed

Using && with spread operator causes "overridden" error if one of the types is "any" #39113

mastrzyz opened this issue Jun 17, 2020 · 10 comments · Fixed by #39529
Assignees
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mastrzyz
Copy link

mastrzyz commented Jun 17, 2020

We are having problems with TypeScript 3.9 upgrade for our repositories and the spread operator and "&&" with any types. TypeScript compiler says the value will be always overridden even though an any type isn't 100% always null/undefined.

TypeScript Version: 3.9.5
Search Terms:

  • specified more than once, so this usage will be overwritten.
  • any type and spread operator

Code

Doesn't work

let isTreeHeader : any = null!;
function foo(){
    return {
        display: "block",
        ...(isTreeHeader && {
          display: "flex",
        })
    }
}
foo()

Works

let isTreeHeader : number = null!;
function foo(){
    return {
        display: "block",
        ...(isTreeHeader && {
          display: "flex",
        })
    }
}
foo()

Expected behavior:

any type can be undefined or can have a non nullable value so we shouldn't get an error with the spread operator

Actual behavior:

'display' is specified more than once, so this usage will be overwritten.ts(2783)

Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=2&pc=22#code/DYUwLgBAlgzgKgJxCAEiAhgExAiAuCdAOwE8IBeCIgV2GAEIBuAKADNqiBjMKAeyIitevABQBKAN7MISMNQQCpETLAAOwdCQIAiAEbBenANbaANNIB0VkbETI0WHBABkziEpUx1mna1AAPM2kAXzEQ5mC2YXEgA

Related Issues:

@mastrzyz mastrzyz changed the title Using && with spread operator causes "overridden" error if one of the types is "any Using && with spread operator causes "overridden" error if one of the types is "any" Jun 17, 2020
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 17, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 17, 2020
@mastrzyz
Copy link
Author

mastrzyz commented Jul 8, 2020

@andrewbranch is there any guidance for this issue in the time currently.

We are on TS 3.8 but would really want to upgrade to TS 3.9 to get the speed and developer improvements.

Is there an acceptable workaround :)

@mastrzyz mastrzyz closed this as completed Jul 8, 2020
@andrewbranch
Copy link
Member

@andrewbranch andrewbranch reopened this Jul 8, 2020
@mastrzyz
Copy link
Author

mastrzyz commented Jul 9, 2020

Thanks, that will work for us!

Unfortunately after adding that fix to some of our instances we are getting an OOM from the TypeScript compiler.

Will try and get a isolated repro case and file a new issue 👍

@andrewbranch
Copy link
Member

@mastrzyz interesting, you get an OOM going from 3.8 to 3.9?

@mastrzyz
Copy link
Author

mastrzyz commented Jul 9, 2020

@andrewbranch I get the OOM in TS 3.9 when trying to use the workaround with "!!". The file is rather huge so I have been struggling so far to get an isolated repro.

@andrewbranch
Copy link
Member

@dotansimha yep, it was fixed in 4.1 (see the milestone on this issue)

@mastrzyz
Copy link
Author

mastrzyz commented Sep 8, 2020

@andrewbranch I'm wondering if it would be feasible to backport this to TS 3.9?

TS 4.1 is far off and even 4.0 for us is going to be a big change to get onboard.

@andrewbranch
Copy link
Member

No, for the same reason it didn’t go into 4.0 post 4.0-beta—because it was a breaking change. For what it’s worth, 4.0 didn’t contain more breaking changes than any other typical release. I’ve heard anecdotal evidence that it was an easy upgrade—out of curiosity, is there something in it that you know of that makes it difficult?

@mastrzyz
Copy link
Author

mastrzyz commented Sep 9, 2020

Yeah a lot of the changes in TS 4.0 are relatively easy to implement but we have a lot of friction with :
#33509

We have a very large codebase and many instances of overriding an external libraries properties with accessors.

I've been trying to follow the guide to fix them but I think I encountered another TypeScript bug.
#40440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants