Skip to content

non-null assertions break CFA #36958

Description

TypeScript Version: 3.7.x-dev.20200221

Search Terms:

Code

const m = ''.match('');
m?.[0] && m[0];
m?.[0]! && m[0];
m?.[0].length! > 0 && m[0];
m?.[0].split('').slice() && m[0];
m?.[0].split('')!.slice() && m[0];

Expected behavior:

const m = ''.match('');
m?.[0] && m[0]; // ok
m?.[0]! && m[0]; // ok
m?.[0].length! > 0 && m[0]; // ok
m?.[0].split('').slice() && m[0]; // ok
m?.[0].split('')!.slice() && m[0]; // ok

Actual behavior:

const m = ''.match('');
m?.[0] && m[0]; // ok
m?.[0]! && m[0]; // error
m?.[0].length! > 0 && m[0]; // error
m?.[0].split('').slice() && m[0]; // ok
m?.[0].split('')!.slice() && m[0]; // error

Playground Link: http://www.typescriptlang.org/play/index.html?ts=3.9.0-dev.20200221&ssl=5&ssc=34&pln=4&pc=28#code/MYewdgzgLgBAtjAvDA5CgdHAhlYALACjQEoBuAKDgH50BtABgF0YAyF+Bxi6upgQlbs4nbjU7oANgFMwAcyh4BAPhj1BHJqN6N0EAA4SAllCIpiuo8CkFi64Zspimug8dPE+Fw1Zt2RQA

Related Issues:

Activity

  1. falsandtru commented on Feb 22, 2020

    @falsandtru
    ContributorAuthor
  2. macabeus commented on Mar 4, 2020

    @macabeus

    What is CFA?

  3. DanielRosenwasser commented on Mar 4, 2020

    @DanielRosenwasser
    Member

    control flow analysis

  4. 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

    BugA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions