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

Error in a case without type annotation. #3666

Closed
lacolaco opened this issue Jun 29, 2015 · 2 comments
Closed

Error in a case without type annotation. #3666

lacolaco opened this issue Jun 29, 2015 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@lacolaco
Copy link

Playground

interface PolymerElement {
  properties?: { [propName: string]: StringConstructor|PolymerElementProperty };
}

interface PolymerElementProperty {
  type: StringConstructor;
}

// Why is this incorrectly implements?
class WithoutTypeAnnotation implements PolymerElement {
    properties = {
        prop1: String,
        prop2: {
            type: String
        }
    };
}

class WithTypeAnnotation implements PolymerElement {
    properties:{ [propName: string]: StringConstructor|PolymerElementProperty } = {
        prop1: String,
        prop2: {
            type: String
        }
    };
}

Both properties are same object, but tsc occurs error in a case without type annotation. Why?

Thanks.

@RyanCavanaugh
Copy link
Member

Necessary background: http://stackoverflow.com/questions/22077023/why-cant-i-indirectly-return-an-object-literal-to-satisfy-an-index-signature-re

The root problem here is that we don't contextually type class property initializers with the type the property "should" have from an implements or extends clause. Without a contextual type on the object literal, the property is inferred to not have an index signature.

Logged #3667 as this has been a long-standing pain point.

@lacolaco
Copy link
Author

Thanks, Ryan. I understood the problem's background.
I hope it'll be resolved someday.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jun 29, 2015
@mhegazy mhegazy closed this as completed Jun 29, 2015
@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants