Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining types broken? #19043

Closed
garrettm opened this issue Oct 9, 2017 · 1 comment
Closed

Combining types broken? #19043

garrettm opened this issue Oct 9, 2017 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@garrettm
Copy link

garrettm commented Oct 9, 2017

TypeScript Version: 2.5.3+
TSC works as expected in 2.5.2, unexpected behavior seen in 2.5.3 and @next (typescript@2.6.0-dev.20171007)

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'.

@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 9, 2017
@mhegazy mhegazy added this to the TypeScript 2.6.1 milestone Oct 9, 2017
@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned sandersn Oct 10, 2017
@ahejlsberg
Copy link
Member

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

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Oct 11, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants