Skip to content
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

incompatible types error unless I use an inline object literal for a dictionary object #7759

Closed
robianmcd opened this issue Apr 1, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@robianmcd
Copy link

TypeScript Version:
1.8.7

Code

interface Test {
    field: {[key: string]: string};
}

var test: Test;
var foo = {qwerty: 'qwerty'};

test = {
    field: foo
};

Expected behavior:
I don't see any errors.

Actual behavior:
I get the following error:

app\app.ts(46,1): error TS2322: Type '{ field: { qwerty: string; }; }' is not assignable to type 'Test'.
Types of property 'field' are incompatible.
Type '{ qwerty: string; }' is not assignable to type '{ [key: string]: string; }'.
Index signature is missing in type '{ qwerty: string; }'.

If I modify my code to this then I don't get an error

interface Test {
    field: {[key: string]: string};
}

var test: Test;

test = {
    field: {qwerty: 'qwerty'}
};
@robianmcd robianmcd changed the title incompatible types error unless I use an object literal for a dictionary object incompatible types error unless I use an inline object literal for a dictionary object Apr 1, 2016
@DanielRosenwasser
Copy link
Member

Thanks but this looks like a duplicate of #6041. Should be fixed in our nightlies. Give it a try with npm install -g typescript@next!

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Apr 1, 2016
@robianmcd
Copy link
Author

Thanks I'll give that a shot

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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

2 participants