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:
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)
Related Issues:
@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 :)
Sure: https://www.typescriptlang.org/play/#code/DYUwLgBAlgzgKgJxCAEiAhgExAgXBdAOwE8IBeCQgV2GAEIBuAKADMrCBjMKAe0IhY8eACgCUEAN5MIMiEjBUE-KbNURMsAA7B0xfACIARsB4cA1voA00tTIB0D4XTqxEyNFhwQAZN8k3bVQ0YbV0DFlAADysAtQBfUVi4pmTBEVEgA
I assume you didn鈥檛 mean to close this 馃槃
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 馃憤
@mastrzyz interesting, you get an OOM going from 3.8 to 3.9?
@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.
Same here, getting this with TS 4.0.2, it failing builds.
Here's a reproduction:
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAEzgSSgCjgB1ggZwC5EBvROANwFMAnWmZagQRIEMwBPAGgpvsbUAQuy6IAvgEoyAWABQiRYlrUoIWklLylOxGxIByKNQJQD3bbsUAjQ8dPnLVgHSvseeGALOqdBk2ZEADIgsj1DXwEmAwlJCwUrRFdnd3wvH35-YWDQ8ltEA0ismKl4nXEAbnlxeSA
@dotansimha yep, it was fixed in 4.1 (see the milestone on this issue)
@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.
No, for the same reason it didn鈥檛 go into 4.0 post 4.0-beta鈥攂ecause it was a breaking change. For what it鈥檚 worth, 4.0 didn鈥檛 contain more breaking changes than any other typical release. I鈥檝e heard anecdotal evidence that it was an easy upgrade鈥攐ut of curiosity, is there something in it that you know of that makes it difficult?
Yeah a lot of the changes in TS 4.0 are relatively easy to implement but we have a lot of friction with :
https://github.com/microsoft/TypeScript/pull/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.
https://github.com/microsoft/TypeScript/issues/40440