Typescript: Combining types broken?

Created on 9 Oct 2017  路  1Comment  路  Source: microsoft/TypeScript



TypeScript Version: 2.5.3+
TSC works as expected in 2.5.2, unexpected behavior seen in 2.5.3 and @next ([email protected])

Code

type B = {b: string}

const flowtypes = <A>(b: B) => {
  type Combined = A & B

  const combined = (fn: (combined: Combined) => void) => null
  const literal = (fn: (aPlusB: A & B) => void) => null

  return {combined, literal}
}

const {combined, literal} = flowtypes<{a: string}>({b: 'b-value'})

literal(aPlusB => {
  aPlusB.b
  aPlusB.a
})

combined(comb => {
  comb.b
  comb.a
})

Expected behavior:
Both literal and combined should produce the same behavior, and properties a and b should be accessible on the argument for both.

Actual behavior:
comb.a is unaccessible:
test.ts(21,8): error TS2339: Property 'a' does not exist on type 'Combined'.

Bug Fixed

Most helpful comment

This is caused by an optimization in #18231 that is a little too optimistic. I will take a look.

>All comments

This is caused by an optimization in #18231 that is a little too optimistic. I will take a look.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roam-Cooper picture Roam-Cooper  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

remojansen picture remojansen  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

wmaurer picture wmaurer  路  3Comments