Skip to content

Code used to work but doesn't in nightly #12584

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

Closed
basarat opened this issue Nov 30, 2016 · 5 comments · Fixed by #12595
Closed

Code used to work but doesn't in nightly #12584

basarat opened this issue Nov 30, 2016 · 5 comments · Fixed by #12595
Labels
Bug A bug in TypeScript

Comments

@basarat
Copy link
Contributor

basarat commented Nov 30, 2016

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

interface CSSProps  {
  color?: string
}
interface NestedCSSProps extends CSSProps {
  nested?: NestedSelector
}
interface NestedSelector  {
  [selector: string]: CSSProps | undefined;
}

let stylen: NestedCSSProps;


// ok
stylen = {
  nested: {
    '&:hover': {
      color: 'red'
    }
  }
}


// does error
stylen = {
  nested: {
    '&:hover': {
      colour: 'red'
    }
  }
}

Works in playground http://www.typescriptlang.org/play/#src=interface%20CSSProps%20%20%7B%0A%20%20color%3F%3A%20string%0A%7D%0Ainterface%20NestedCSSProps%20extends%20CSSProps%20%7B%0A%20%20nested%3F%3A%20NestedSelector%0A%7D%0Ainterface%20NestedSelector%20%20%7B%0A%20%20%5Bselector%3A%20string%5D%3A%20CSSProps%20%7C%20undefined%3B%0A%7D%0A%0Alet%20stylen%3A%20NestedCSSProps%3B%0A%0A%0A%2F%2F%20ok%0Astylen%20%3D%20%7B%0A%20%20nested%3A%20%7B%0A%20%20%20%20'%26%3Ahover'%3A%20%7B%0A%20%20%20%20%20%20color%3A%20'red'%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0A%0A%2F%2F%20does%20error%0Astylen%20%3D%20%7B%0A%20%20nested%3A%20%7B%0A%20%20%20%20'%26%3Ahover'%3A%20%7B%0A%20%20%20%20%20%20colour%3A%20'red'%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D

Expected behavior:
Works in nightly

Actual behavior:
Doesn't work in nightly. You don't get an error for the colour typo

@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 30, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.3 milestone Nov 30, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Nov 30, 2016

@vladima can you take a look.

@basarat
Copy link
Contributor Author

basarat commented Nov 30, 2016

Quick question: what is the version in the playground 🌹

@vladima
Copy link
Contributor

vladima commented Nov 30, 2016

it seems that it was broken a while back. Error is reproduced when strict null checks are enabled

@vladima
Copy link
Contributor

vladima commented Nov 30, 2016

simplified repro

interface CSSProps  {
  color?: string
}
interface NestedCSSProps {
  nested?: NestedSelector
}
interface NestedSelector  {
  prop: CSSProps;
}

let stylen: NestedCSSProps = {
  nested: { prop: { colour: 'red' } }
}

@basarat
Copy link
Contributor Author

basarat commented Dec 1, 2016

Error is reproduced when strict null checks are enabled

Nice. That sort of explains why it works with strictNullChecks if nested isn't optional.

interface CSSProps  {
  color?: string
}
interface NestedCSSProps {
  nested: NestedSelector
}
interface NestedSelector  {
  prop: CSSProps;
}

// Errors now even with strictNullChecks
let stylen: NestedCSSProps = {
  nested: { prop: { colour: 'red' } }
}

Something about nullability analysis is throw it off 🌹 Hope its fixed soon ❤️

@mhegazy mhegazy modified the milestones: TypeScript 2.2, TypeScript 2.1.3 Dec 1, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants