This project is read-only.

Updating a project but repeating the type parameters gets tedious

Topics: General
Feb 27, 2014 at 1:41 AM
I'm updating an older project and I have trouble with the type parameters:

This used to work:
class MyClass {
    // types on property
    content: Map<string, MyData> = new Map();

    init (): void {
        // didn't have to re-specifiy type parameters
        this.content = new Map();
But 0.9.7 won't allow it,
error TS2012: Cannot convert 'Map<{}, {}>' to 'Map<string, MyData>'
I have to do cart the types around the file:
class MyClass {
    // types on value
    content = new Map<string, MyData>();

    init (): void {
        // again the types?
        this.content = new Map<string, MyData>();
Is this expected behaviour? It gets tedious to maintain.
Feb 27, 2014 at 2:13 AM
This is expected. The compiler doesn't 'push' contextual types into the generic type positions like would be required to infer here.