Skip to content

Effect plugin: floatingEffect's type query adds TS18048/TS2532 next to TS2722 #112

Open

Description

@BenKnill

Note

🤖 Claude Opus 5.5 writing on behalf of Ben

With the Effect plugin on, a statement that calls a possibly-undefined function gets an extra TS18048 (or TS2532)
next to the TS2722 that tsc reports. Turning off floatingEffect alone removes it.

Repro

tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noEmit": true,
    "types": [],
    "plugins": [{ "name": "@effect/language-service" }]
  },
  "files": ["a.ts"]
}

a.ts:

declare const f: (() => void) | undefined;
f();

declare const fs: Array<() => void>;
fs[0]();

export {};

tsc -p tsconfig.json --pretty false with typescript@7.1.0-beta (the pin):

a.ts(2,1): error TS2722: Cannot invoke an object which is possibly 'undefined'.
a.ts(5,1): error TS2722: Cannot invoke an object which is possibly 'undefined'.

tsc-rs main (91f3d02), both the native tsgo and the wasm module through runTsc:

a.ts(2,1): error TS2722: Cannot invoke an object which is possibly 'undefined'.
a.ts(2,1): error TS18048: 'f' is possibly 'undefined'.
a.ts(5,1): error TS2532: Object is possibly 'undefined'.
a.ts(5,1): error TS2722: Cannot invoke an object which is possibly 'undefined'.
  • Without the plugin entry, or with "diagnosticSeverity": { "floatingEffect": "off" } in it, tsc-rs prints only
    the two TS2722.
  • We turned each of the 124 rules off in turn, and only floatingEffect changes the output.
  • await g(); on a possibly-undefined g gets the same extra TS18048.

Cause (read from the source, not traced)

  • detect_floating_effect asks TypeParser::get_type_at_location for the type of the statement's expression, after
    the file's check.
  • For a call, get_type_of_expression takes the quick path in get_quick_type_of_expression. That path calls
    check_non_null_expression on the callee, which reports TS18048 or TS2532 into the checker's diagnostics.
  • The normal check of a call statement does not take this path, so tsc prints only TS2722. tsc itself prints the
    same TS2722 and TS18048 pair for const r = f();, because a variable initializer does take the quick path.

get_type_at_location already skips one side effect of this kind (TS2731 on the template of a tagged template).
This is another one.

The reference

We did not run Effect-TS/tsgo, so we have not seen its output. Its source at 0.51.1, the version this port follows,
seems to have the same path:

  • its GetTypeAtLocation calls checker.GetTypeAtLocation directly;
  • patch 002 runs the rules on the same checker at the end of checkSourceFile.

Effect-TS/tsgo#860, first released in 0.53.2, makes GetTypeAtLocation read the expression types recorded during
the check first. Its description says that querying every expression after the check adds no diagnostics. So a later
Effect pin, or a port of that change, may remove this.

Impact

In Effect-TS/effect at 0d083ba, whose tsconfig has the plugin, we saw no extra diagnostics with the repo's own
options. With --noUncheckedIndexedAccess we saw 23 extra, in 2 configs. Any project with the plugin that calls a
possibly-undefined function as a statement gets a second error at the same position.

Measured on macOS arm64, with tsc-rs built from main at 91f3d02.

Activity

  1. joaomarcelo09 commented on Oct 29, 2026

    @joaomarcelo09

    Note

    🤖 Claude Opus 5.5 writing on behalf of Joao

    Reproduced on main (91f3d02), Linux x86_64. The release tsgo with the plugin prints the extra TS18048 on f(); and await g(); and the extra TS2532 on fs[0]();. typescript@7.1.0-beta prints only the TS2722s (and the TS2722 + TS18048 pair on const r = f();).

    #113 ports Effect-TS/tsgo#860 ahead of the 0.51.1 pin: the check records each final expression type, recording pauses while the rules run, and get_type_at_location reads the record first. With it the output equals tsc on the repro. The Effect case suite (1,060 cases) passes. PORTING.md lists the port as a difference from 0.51.1. If you'd rather take #860 with an Effect pin bump, the PR can wait for that.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions