Skip to content

Star-imported module should conform to the type of a string-indexed object #17622

Closed
@pelotom

Description

@pelotom

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!

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions