[P2] Checker: optional member calls reject string-or-undefined receivers

Open
#3,462 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp, typescript
Domain
compilers

Research direction

The payload names no source file, so start by reproducing the snippet with --no-tsconfig --lib es2022,dom in both interpret and compile modes. Then find where the message "Cannot invoke an object which is possibly 'undefined'" is produced in the checker. Done when the snippet prints true in both modes and the optional call on a string | undefined receiver no longer errors.

Written by the indexing model from the issue text.

Description

bug priority: P2

The checker rejects a valid optional member call on a nullable string receiver.

function run(value: string | undefined) {
    console.log(value?.includes("x") === undefined);
}
run(undefined);

Strict TypeScript accepts this program and Node prints true. Both SharpTS interpretation and compilation reject it before execution with Cannot invoke an object which is possibly 'undefined'.

Reproduced with --no-tsconfig --lib es2022,dom. The optional member access should short-circuit the following call when the receiver is undefined. This report contains no non-null assertion, grouped optional-call boundary, or optional argument/default behavior.

Dominant language
C#
Stars
156
Forks
4
Avg merge
13h 33m
Merged PRs (30d)
45

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nickna/SharpTS

All issues in nickna/SharpTS

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.