2

in the following code:


const styles = {
    a: 1,
    b: '100%',
    c: 'invalid',
  } as const

  const styleHolder: { a: number, b: string } = styles

  const styleHolder2: { a: number, b: string } = {
    a: 1,
    b: '100%',
    c: 'invalid',
  }

Why does styleHolder2 throw an error on c while styleHolder does not. Is there anything I can do to get the same error on styleHolder?

example in typescript playground

jcalz
  • 264,269
  • 27
  • 359
  • 360
Chris Drackett
  • 1,248
  • 2
  • 10
  • 22
  • 2
    Please see [this question/answer](https://stackoverflow.com/questions/61841687/why-does-typescript-not-throw-an-error-when-the-function-argument-type-is-mismat). If it does not address your question, please edit this question to highlight the differences. – jcalz Apr 06 '21 at 18:10

0 Answers0