-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
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 = 5Conceptually 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!
Connormiha
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue