Skip to content

error TS2339: Property 'length' does not exist on type 'never' #33138

Closed
@doberkofler

Description

@doberkofler

TypeScript Version: 3.6.2

Search Terms:

Code

function getValue(): string {
	return '1';
}

function isNumber(value: any): value is number {
	return typeof value === 'number' && !Number.isNaN(value) && Number.isFinite(value);
}

function main() {
	let value = getValue();

	if (isNumber(value) && value.length === 4) {
		value++;
	}
}

main();

Expected behavior:
The compare in the line if (isNumber(value) && value.length === 4) in the above example would always fail but did compile without type error in TypeScript 3.5.3.

Actual behavior:
In TypeScript 3.6.2 the line generates error TS2339: Property 'length' does not exist on type 'never' and I do not understand why this would be a type error?

Playground Link:

Related Issues:

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