Skip to content

Type of variable incorrectly any when used in function body in its own initializer #445

@vvakame

Description

@vvakame

reproduction code.

interface IResource<T> {
    $save(): void;
}
interface IResourceClass<T> {
    new (): T;
    query(callback: Function): IResourceArray<T>;
}
interface IResourceArray<T> extends Array<T> {
}

function makeClass<T, U>(): U {
    return null;
}

interface IFoo {
    foo: string;
}
interface IFooResource extends IResource<IFooResource>, IFoo {
}
interface IFooResourceClass extends IResourceClass<IFooResource> {
}

var Clazz = makeClass<IFooResource, IFooResourceClass>();
var array = Clazz.query(() => {
    var obj1 = array[1];
    obj1.foo;
    obj1.$save();
    // I'm expected an error occured following line.
    // but tsc 1.0.1 and master/HEAD are compiled it.
    obj1.notExsists;
});

var obj2 = array[1];
obj2.foo;
obj2.$save();
// I'm expected an error occured following line.
// but tsc master/HEAD are compiled it. tsc 1.0.1 are decline it.
obj2.notExsists;

in tsc 1.0.1

$ tsc --version
Version 1.0.1.0
$ tsc test.ts
/Users/vvakame/tmp/test.ts(38,6): error TS2094: The property 'notExsists' does not exist on value of type 'IFooResource'.

in master/HEAD 2a106bf

$ node ~/work/TypeScript/built/local/tsc.js test.ts
$ echo $?
0

in playground (I think playground are works perfectly)
http://goo.gl/4jjVHi

in real world
https://gist.github.com/vvakame/1272d6b94febc18d0bd4
https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular-resource.d.ts

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptBy DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadSpecIssues related to the TypeScript language specification

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions