You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression - default initializer of {} ruins type intersected with object #49480
exportinterfaceBarProps{barProp?: string;}exportinterfaceFooProps{fooProps?: BarProps&object;}declareconstfoo: FooProps;const{ fooProps ={}}=foo;fooProps.barProp;// ~~~~~~~// error! Property 'barProp' does not exist on type '{}'.
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
‼️ Exception: Error - Did not find a source file for /home/runner/work/TypeScript/TypeScript/index.ts
Error: Did not find a source file for /home/runner/work/TypeScript/TypeScript/index.ts
at Object.updateFile (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:6876:15)
at _loop3 (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:1738:9)
at twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:1744:17)
at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:777:44
at runTwoslashRequests (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:744:56)
at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:2169:75)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Yup, this is caused by #49119. It modified simpleTypeRelatedTo to consider {} a supertype of object in the strictSubtypeRelation. But really that should only be true for a non-fresh {}. In other words, we want fresh {} <: object <: {} in the strict subtype relation (i.e. fresh {} is a subtype of object which is a subtype of {}).
Also, for some reason we remove object literal freshness from the source side when relating to an intersection on the target side. Lost in history as to why, removing it doesn't change any baselines.
In combination, those two changes fix the issue. I will put up a PR.
Daniel Rosenwasser (@DanielRosenwasser) Argh, yes. I always read <: as is-supertype-of because it looks like an inheritance tree on its side. But you're right, it should be the other way around. I'll correct it.
Also, on Anders Hejlsberg (@ahejlsberg)'s note, I've personally always felt like the arrows in inheritance diagrams go in the wrong direction (cause <- effect is weird), so I find fresh {} ≤ object ≤ {} to actually be easier to read.
Reacted by Daniel Rosenwasser, Ryan Cavanaugh and Grant Dickinson
Activity
DanielRosenwasser commentedon Jun 10, 2022
TypeScript Bot (@typescript-bot) bisect good v4.7.3 bad main
DanielRosenwasser commentedon Jun 10, 2022
Forgot to add
strictNullChecks, but it shouldn't matter.typescript-bot commentedon Jun 10, 2022
The change between v4.7.3 and main occurred at 5aa0053.
typescript-bot commentedon Jun 10, 2022
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in the issue body running against the nightly TypeScript.
Issue body code block by Daniel Rosenwasser (@DanielRosenwasser)
Historical Information
👍 Compiled
fatcerberus commentedon Jun 10, 2022
That’s the second time it’s done that…
weswigham commentedon Jun 10, 2022
methinks the twoslasher is broken with latest TS - the bug workbench does the same thing.
DanielRosenwasser commentedon Jun 10, 2022
First repros on
typescript@4.8.0-dev.20220528Merge list on May 27th is https://github.com/microsoft/TypeScript/pulls?q=is%3Apr+merged%3A2022-05-27+is%3Aclosed
Likely introduced by #49119
ahejlsberg commentedon Jun 12, 2022
Yup, this is caused by #49119. It modified
simpleTypeRelatedToto consider{}a supertype ofobjectin thestrictSubtypeRelation. But really that should only be true for a non-fresh{}. In other words, we wantfresh {} <: object <: {}in the strict subtype relation (i.e.fresh {}is a subtype ofobjectwhich is a subtype of{}).Also, for some reason we remove object literal freshness from the source side when relating to an intersection on the target side. Lost in history as to why, removing it doesn't change any baselines.
In combination, those two changes fix the issue. I will put up a PR.
DanielRosenwasser commentedon Jun 13, 2022
You mean the reverse, right?
fresh {}≤object≤{}ahejlsberg commentedon Jun 13, 2022
Daniel Rosenwasser (@DanielRosenwasser) Argh, yes. I always read
<:as is-supertype-of because it looks like an inheritance tree on its side. But you're right, it should be the other way around. I'll correct it.DanielRosenwasser commentedon Jun 13, 2022
GitHub now lets you do Mermaid diagrams. This should make it easier to read 😄
graph BT; emptyObject("{}"); nonPrimitive("object"); freshEmptyObject("fresh {}"); freshEmptyObject --> nonPrimitive --> emptyObject;fatcerberus commentedon Jun 13, 2022
I've never heard this term before.
Also, on Anders Hejlsberg (@ahejlsberg)'s note, I've personally always felt like the arrows in inheritance diagrams go in the wrong direction (
cause <- effectis weird), so I findfresh {} ≤ object ≤ {}to actually be easier to read.RyanCavanaugh commentedon Jun 13, 2022
It's super weird because I want class arrows to go one way but subtyping arrows to go the other way. Human brains are a mess.