Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited tags
Link
Jack Bashford
  • 44.3k
  • 11
  • 56
  • 84
Source Link
David Hellsing
  • 108.7k
  • 44
  • 181
  • 214

Object.keys using numbers in typescript

type Foo = { [key: number]: string }
const foo: Foo = { 100: 'foo', 200: 'bar' }
const sizes: number[] = Object.keys(foo)

Gives me:

Type 'string[]' is not assignable to type 'number[]

Why does Typescript assume string[]? And what is the correct way of creating an array of numbers here?

lang-js

AltStyle によって変換されたページ (->オリジナル) /