Closed
Description
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Suppose I have this module:
// foo.ts
export const x = 3
export const y = 5
Conceptually this module represents a map of strings to numbers, { [k: string]: number }
, however if I try to use it directly as such I get a type error:
// bar.ts
import * as foo from './foo'
function f(map: { [k: string]: number }) {
// ...
}
f(foo)
//^^^ Argument of type 'typeof "/Users/tom/code/example/src/foo"' is not assignable to parameter of type '{ [k: string]: number; }'.
// Index signature is missing in type 'typeof "/Users/tom/code/example/src/foo"'.
Fortunately there is a workaround: I can simply spread and recompose the module to make it conform to the expected type:
f({ ...foo }) // this type checks!
However it'd be nice if the more straightforward approach just worked!