Closed
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"
}
}
}