Skip to content

Breaking change in 2.1: Node.firstChild can now be null #12720

Closed
@felixfbecker

Description

@felixfbecker

TypeScript Version: 2.1.4

This code snippet used to compile fine in 2.0 with strictNullChecks, but now errors in 2.1:

if (documentElement.hasChildNodes() && documentElement.firstChild.nodeName === 'error') {
}

I agree that firstChild can in fact be null (even though in this case I checked with hasChildNodes), but this is a breaking change introduced in a minor version.

Workaround: check with documentElement.firstChild && or add a ! in the cases where I know from the protocol that the element will have a child node.

Full file: https://github.com/felixfbecker/vscode-php-debug/blob/master/src/xdebugConnection.ts
Failing build: https://travis-ci.org/felixfbecker/vscode-php-debug/builds/182024998

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking ChangeWould introduce errors in existing codeDocsThe issue relates to how you learn TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions