Skip to content

operator === cannot be applied to types false and true #24621

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
zerkms opened this issue Jun 2, 2018 · 4 comments
Closed

operator === cannot be applied to types false and true #24621

zerkms opened this issue Jun 2, 2018 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zerkms
Copy link

zerkms commented Jun 2, 2018

TypeScript Version: 3.0.0-dev.201xxxxx

Search Terms:

Code

var a = false;

if (a === true) {
    console.log('foo')
}

Expected behavior:
Given typescript is a superset of JS it must compile

Actual behavior:
It fails with the operator === cannot be applied to types false and true

Playground Link:
https://www.typescriptlang.org/play/#src=var%20a%20%3D%20false%3B%0D%0A%0D%0Aif%20(a%20%3D%3D%3D%20true)%20%7B%0D%0A%20%20%20%20console.log('foo')%0D%0A%7D

Related Issues:
It was at least reported at #11178 but for some reason the original poster has closed it

@Zzzen
Copy link
Contributor

Zzzen commented Jun 2, 2018

var a = 1;
a = "1"

is valid js code, and yet it should not compile.

@zerkms
Copy link
Author

zerkms commented Jun 2, 2018

Then the main page with its

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

and documentation should be corrected correspondingly?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 2, 2018

Given typescript is a superset of JS it must compile

it does. the compiler will generate JavaScript fro your input that is identical. Compiler errors do not stop the generation of output. the compiler will however warn you about possible issues. that applies to almost all errors in TS.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 2, 2018
@zerkms
Copy link
Author

zerkms commented Jun 3, 2018

Compiler errors do not stop the generation of output

unless --noEmitOnError is used.

But I see the point, thanks.

@zerkms zerkms closed this as completed Jun 3, 2018
@microsoft microsoft locked and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants