TypeScript: TypeScript Language Server False Positive Error Reporting

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.87.0
  • OS Version: Ubuntu 22.04

Steps to Reproduce:

  1. Clone the project git clone https://github.com/DScheglov/res-test.git
  2. Open the VS Code: code res-test
  3. Install dependencies (in terminal): npm i
  4. Open file ./src/index.ts

The following errors are shown: image

These errors are false positive:

  1. project is configured to use the same typescript compiler as a project. See .vscode/settings.json
  2. project is compiled successfully via terminal: npx tsc (no errors)
  3. errors are gone after TS Language Server is restared (Ctrl + Shift + P , TypeScript: Restart TS Server)
  4. errors go back after any touch of the file (just add a space).

There is not such problem in WebStorm image (Sorry, I have to check)

Errors are not displayed in the TS Playground as well: Playground

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 5
  • Comments: 25 (13 by maintainers)

Most upvoted comments

Tracking as https://github.com/Effect-TS/effect is also hit by this

I working on a fix for this, I’ll put something up later this afternoon.

Unfortunately it seems like it doesn’t fix the issue, rather it does but it makes it appear in a different place, the return of the generator

Screenshot 2024-04-26 at 09 05 36

It does appear to be the case only if there is no specified return, adding a return keyword makes the issue disappear

https://github.com/microsoft/TypeScript/issues/57903 doesn’t affect Effect as we don’t use async generators (provided I’ve understood the issue correctly)

I’m not sure how their rule works. If it depends on type information (looks like it does) then that error should go away after we fix this one.

Minimized repro

export interface Result<T, E> {
  mapErr<F>(fn: (error: E) => F): Result<T, F>;
  [Symbol.iterator](): Generator<E, T>;
}

declare const okIfObject: (value: unknown) => Result<Record<string, unknown>, 'ERR_NOT_AN_OBJECT'>;
declare const okIfInt: (value: unknown) => Result<number, 'ERR_NOT_AN_INT'>;
export declare function Do2<T, E>(job: () => Generator<E, T>): void;

declare let value: unknown;
Do2(function* () {
  const object = yield* okIfObject(value).mapErr(
    error => 0
  );

  const age = yield* okIfInt(object.age).mapErr(
    error => 0
  );

  return { age };
});