Skip to content

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

Closed

Description

@ExE-Boss

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.

Activity

  1. RyanCavanaugh commented on Apr 1, 2019

    @RyanCavanaugh
    Member

    This is the intended error for this code.

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions