Skip to content

No type checking when generic class/interface do not have any properties and '{}' is used as generic type variable #14320

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

Closed
alhugone opened this issue Feb 26, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@alhugone
Copy link

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
with strictNullChecks

Code

//example 1:
interface MyInterface<T> {
    someMethod: (param1: T) => MyInterface<T>;
}

class MyInterfaceImpl<T> implements MyInterface<T>{
    someMethod = function (param1: T) {
        return new MyInterfaceImpl<T>();
    }
}

let getMyInterface: () => MyInterface<{}> = () => { return new MyInterfaceImpl<{}>(); };

let getString: () => MyInterface<string> = getMyInterface;
let getDate: () => MyInterface<Date> = getMyInterface;
let getNumber: () => MyInterface<number> = getMyInterface;


//example 2:
let getPromise1: () => Promise<{} | number> = () => { return Promise.resolve({}) };

let getStringP1: () => Promise<string> = getPromise1
let getDateP1: () => Promise<Date> = getPromise1
let getNumberP1: () => Promise<number> = getPromise1


//example 3:
let getPromise2: () => Promise<{} | number| undefined | null> = () => { return Promise.resolve({}) };

let getStringP2: () => Promise<string> = getPromise2
let getDateP2: () => Promise<Date> = getPromise2
let getNumberP2: () => Promise<number> = getPromise2

Expected behavior:
Should not compile with error like 'Type () =>Promise<X> is not assignable to type '() => Promise<Y>'.
Actual behavior:
Compiles.

@alhugone
Copy link
Author

alhugone commented Feb 26, 2017

#14298 - I think it is related.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 27, 2017

Duplicate of #13970

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 27, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants