-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
object literal method union reduce
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
Playground link with relevant code
π» Code
let a = [
{ foo: 0, m() { } },
{ bar: 1 }
]
declare let n: number
a[n].mπ Actual behavior
TypeScript behaves as if m in present on a[n] when trying to access in a[n].m (as it does for foo and bar as well), but generated declarations don't reflect this:
declare let a: ({
foo: number;
m(): void;
bar?: undefined;
} | {
bar: number;
foo?: undefined;
})[];With the above declaration for a (from generated declarations), we couldn't access a[n].m (PL).
Tooltips also display the same type as declarations omitting m in the second constituent of the union.
π Expected behavior
Methods in object literals should behave the same as properties when the type of the array is inferred (if a method is missing in one of the objects, an optional member with type undefined should be inferred:
declare let a: ({
foo: number;
m(): void;
bar?: undefined;
} | {
bar: number;
foo?: undefined;
m?: undefined;
})[];robpalme, jcalz and RyanCavanaugh
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts filesFix AvailableA PR has been opened for this issueA PR has been opened for this issue