Skip to content
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

Promise<number> is Promise<string> #6316

Closed
falsandtru opened this issue Jan 2, 2016 · 3 comments
Closed

Promise<number> is Promise<string> #6316

falsandtru opened this issue Jan 2, 2016 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@falsandtru
Copy link
Contributor

Is there any way to resolve the following weak typings?

type A = boolean;
type AB = boolean|number;
class C<T> {
    g: T;
}

var c: C<A> = <C<AB>>null; // error
var p: PromiseLike<A> = <PromiseLike<AB>>null; // should be an error
@falsandtru falsandtru changed the title Some standard type definitions are buggy Some standard type definitions omit the type checking Jan 2, 2016
@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Jan 7, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Jan 7, 2016

not that i can think of.

@falsandtru
Copy link
Contributor Author

TypeScript said, Promise<number> is Promise<string>.

var s: PromiseLike<number | string> = <PromiseLike<string>>null;
var n: PromiseLike<number> = <PromiseLike<number | string>>s; // should be an error

@falsandtru falsandtru changed the title Some standard type definitions omit the type checking Promise<number> is Promise<string> Jan 8, 2016
@RyanCavanaugh
Copy link
Member

Title is not accurate:

let x: PromiseLike<string>;
let y: PromiseLike<number>;
x = y; // Error

The behavior around string|number happens because of function parameter bivariance; see any number of issues around this already, e.g. #222

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants