Skip to content

Non-null type assertions shouldn't affect optional chaining #34875

Closed
@falsandtru

Description

@falsandtru

cc @ahejlsberg

TypeScript Version: 3.7.x-dev.20191101

Search Terms:

Code

const a = document.querySelector('_')?.textContent!;

Expected behavior:

Type of a is string | undefined.

Actual behavior:

Type of a is string.

This means document.querySelector('_').textContent! is valid and these are the equivalent to document.querySelector('_')!.textContent!.

Playground Link: http://www.typescriptlang.org/play/?ts=3.8.0-dev.20191101&ssl=1&ssc=53&pln=2&pc=23#code/MYewdgzgLgBAhjAvDAJiYBXAtgUzFAOgEcMcAnATwGUcAbHYKEMgCgHIB9NgSgH4CoOAB5QAwuEH4AhAG4gA

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