Skip to content

4.8 regression assigning object literal to intersection of conditional type and object type #50619

Description

@andrewbranch

There's a Stack Overflow question that seems to be related to this PR:

interface Baz {
  foo: { a: number };
}

const createDefaultExample = <K extends keyof Baz>(x: K): Baz[K] & { x: K; } => {
  return { a: 0, x }; // okay in TS4.7, error in TS4.8
}

Playground link

Looks like the fix for #49520 might have broken this. Is it a bug and should this be filed as such? Or is it intended in some way?


EDIT: Looks like the above was fixed by #50261 but this one persists:

type Foo<K> = K extends unknown ? { a: number } : unknown
const createDefaultExample = <K,>(x: K): Foo<K> & { x: K; } => {
  return { a: 1, x: x }; // okay in TS 4.7.4, error in TS 4.8.2
}

Playground link to code

Same question, I guess... bug? Not bug? New issue?

Originally posted by @jcalz in #49503 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions