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

TS2367: Support loose equivalence of 'number' and 'string' #30655

Closed
ExE-Boss opened this issue Mar 30, 2019 · 1 comment
Closed

TS2367: Support loose equivalence of 'number' and 'string' #30655

ExE-Boss opened this issue Mar 30, 2019 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ExE-Boss
Copy link
Contributor

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

  • TS2367: This condition will always return 'false' since the types 'number' and 'string' have no overlap.

Code

declare var aa: string[];
declare var bb: string[];

for (let x = 0; aa[x] && bb[x]; x++) {
	if (aa[x] !== bb[x]) {
		const c	= Number(aa[x]);
		const d	= Number(bb[x]);

		if (c == aa[x] && d == bb[x]) {
			// Do stuff if both strings contain numbers
		}
	}
}

Expected behavior:

TypeScript considers loose equivalence of string and number valid, at least when type checking JavaScript code.

Actual behavior:

.hidden/stuff.ts:9:7 - error TS2367: This condition will always return 'false' since
                       the types 'number' and 'string' have no overlap.

9       if (c == aa[x] && d == bb[x]) {
            ~~~~~~~~~~    ~~~~~~~~~~

Related Issues:

Additional info:

This is a snippet of legacy code that I’m not allowed to change.

@RyanCavanaugh
Copy link
Member

This is the intended error for this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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

2 participants