- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Description
Hi,
I think this is a bug. Please see comments for details:
interface ObjectHash {
    [key: string]: any;
}
// OK   
var defaults: ObjectHash = {
    title: "untitled",
};
// This is error, expected
defaults = ["a"];
declare class Model {
    defaults: ObjectHash
}
// Index signatures of types '{ title: string }' and 'ObjectHash' are incompatibe.
// Why?! Unexpected error.
class MyModel extends Model {
    defaults = {
        title: "untitled"
    };
}
// It works when assigned in the constructor
class MyModel1 extends Model {
    constructor() {
        // OK
        this.defaults = {
            title: "untitled"
        }       
        super();
    }
}
// Trying different way
declare class Model2 {
    // 'defaults' is method
    defaults(): ObjectHash
}
// Same here. Why is this an error? Is this a bug?
class MyModel2 extends Model2 {
    defaults() {
        return {
            title: "untitled"
        }
    }
}Metadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead