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
Index signature lost with empty intersections #27044
Search Terms:
Index signature lost
inconsistent intersections
empty intersections
Code
This is a dumbed-down version of what I have experienced.
Whenever 2 empty-object types are merged, the assumption of a type signature is lost.
typechoices<IChoiceListextends{[key: string]: boolean;}>=IChoiceList&{shoes:boolean;food:boolean;};typeIMyChoiceList={car: true};typeIUnknownChoiceList={};vardefaultChoices: choices<{}>;vardefaultChoicesAndEmpty: choices<{}&{}>;/*Type '{}' does not satisfy the constraint '{ [key: string]: boolean; }'. Index signature is missing in type '{}'.*/varmyChoices: choices<IMyChoiceList>;varmyChoicesAndEmpty: choices<IMyChoiceList&{}>;varunknownChoices: choices<IUnknownChoiceList>;varunknownChoicesAndEmpty: choices<IUnknownChoiceList&{}>;/*Type '{}' does not satisfy the constraint '{ [key: string]: boolean; }'.*/
Expected behaviour:
If {} is assumed to have a compliant type signature, then surely {} & {} should have the same.
Actual behaviour:
Whenever 2 empty-object types are merged, the assumption of a type signature is lost.
Errors commented above are for the single line of code above them.
Activity
poseidonCore commentedon Sep 18, 2018
This appears to be directly related to #20225
RyanCavanaugh commentedon Sep 21, 2018
Anders Hejlsberg (@ahejlsberg) looks like the index signature check needs to be distributive over intersection types?