Skip to content

Object result of import all from module has no index signature #16248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OliverJAsh opened this issue Jun 4, 2017 · 4 comments
Closed

Object result of import all from module has no index signature #16248

OliverJAsh opened this issue Jun 4, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@OliverJAsh
Copy link
Contributor

TypeScript Version: 2.3.4

Given an actions module where each exported member satisfies the type type MyFn = (...args: any[]) => any, when I collect those exports using import *, the resulting object has no index signature, leading to unwanted type errors.

Code

import * as actions from 'actions';
type MyFn = (...args: any[]) => any;
type MyMap = { [key: string]: MyFn };
const myMap: MyMap = actions;

Expected behavior:
No error.

Actual behavior:

Type 'typeof "/Users/OliverJAsh/Development/unsplash-web/app/actions/index"' is not assignable to type 'MyMap'.
  Index signature is missing in type 'typeof "/Users/OliverJAsh/Development/unsplash-web/app/actions/index"'.
@OliverJAsh
Copy link
Contributor Author

One workaround is to spread the object:

import * as actions from 'actions';
type MyFn = (...args: any[]) => any;
type MyMap = { [key: string]: MyFn };
const myMap: MyMap = actions; // error
const myMap2: MyMap = { ...actions }; // no error!

@anticrisis
Copy link

Just ran into the same problem. Thanks for the workaround.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

looks like a duplicate of #17622

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 7, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants