Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected deprecation warning after upgrading to TypeScript v4.2.2 #43053

Closed
Julien-Marcou opened this issue Mar 3, 2021 · 45 comments · Fixed by #43165
Closed

Unexpected deprecation warning after upgrading to TypeScript v4.2.2 #43053

Julien-Marcou opened this issue Mar 3, 2021 · 45 comments · Fixed by #43165
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@Julien-Marcou
Copy link

Julien-Marcou commented Mar 3, 2021

Bug Report

🔎 Search Terms

RxJS Deprecation Warning TSLint ESLint VSCode Signature Doc Tags DocTags

🕗 Version & Regression Information

Since TypeScript v4.2.2, I get deprecation warnings with RxJS, that I was not getting in TypeScript v4.1.5

I first opened an issue on RxJS (here), but it may be a TypeScript issue

💻 Code

import { Observable, Subject } from 'rxjs';

const somethingHappened: Subject<void> = new Subject();
const somethingHappened$: Observable<void> = somethingHappened.asObservable();

// Deprecation warning on the next line
somethingHappened$.subscribe(() => {
  console.log('something happened');
});

somethingHappened.next();

🙁 Actual behavior

When I subscribe to the observable, I get the deprecation warning subscribe is deprecated: Use an observer instead of a complete callback even though I'm not using any complete callback

It occurs with both TSLint v6.1.3 and ESLint v7.21.0 (using eslint-plugin-deprecation v1.2.0)

Here are the signatures for the subscribe method in RxJS v6.6.6 :

subscribe(observer?: PartialObserver<T>): Subscription;
/** @deprecated Use an observer instead of a complete callback */
subscribe(next: null | undefined, error: null | undefined, complete: () => void): Subscription;
/** @deprecated Use an observer instead of an error callback */
subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Subscription;
/** @deprecated Use an observer instead of a complete callback */
subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Subscription;
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;

If I understand this correctly, in my case it should be using this signature :

subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;

Which is not deprecated

🙂 Expected behavior

There should be no deprecation warning

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 4, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.1 milestone Mar 4, 2021
@gspat24
Copy link

gspat24 commented Mar 6, 2021

+1

@nzbin
Copy link

nzbin commented Mar 7, 2021

I have found this issue after upgrade vscode.

@itayperry
Copy link

itayperry commented Mar 7, 2021

Thank you for opening this issue - I have a huge Angular project with endless tslint deprecation warnings 🚀

@idamachmadfaizin
Copy link

I have found this issue with upgrade vscode.

Yeah, I think since version: 1.54.1

@s4r14k
Copy link

s4r14k commented Mar 8, 2021

Same here after upgrade vscode

@ak274
Copy link

ak274 commented Mar 8, 2021

After updating VSCode to 1.54.1. I started seeing these deprecation warnings.

@amosISA
Copy link

amosISA commented Mar 8, 2021

Same here.

@cvarona
Copy link

cvarona commented Mar 8, 2021

Same here

@zulihan
Copy link

zulihan commented Mar 8, 2021

Hi !
Same here.
Visual studio Code:
Version: 1.54.0
Commit: 42e27fe5cdc58539dad9867970326a297eb8cacf
"tslint": "~6.1.0"

@Jonah-Jordan
Copy link

Same here

@adamkoncz
Copy link

Same issue after VSCode update

Version: 1.54.1 (user setup)
Commit: f30a9b73e8ffc278e71575118b6bf568f04587c8
Date: 2021-03-04T22:38:31.419Z

@jrdutton
Copy link

jrdutton commented Mar 8, 2021

Ditto

Version: 1.54.1 (user setup)
Commit: f30a9b73e8ffc278e71575118b6bf568f04587c8
Date: 2021-03-04T22:38:31.419Z

@MikaStark
Copy link

Same as @jrdutton

Version: 1.54.1 (user setup)
Commit: f30a9b73e8ffc278e71575118b6bf568f04587c8
Date: 2021-03-04T22:38:31.419Z

@Julien-Marcou
Copy link
Author

Julien-Marcou commented Mar 8, 2021

VS Code now ships with TypeScript 4.2.2. This major update includes many TypeScript language improvements, along with many improvements and bug fixes for JavaScript and TypeScript tooling.

FYI: The issue is still present with TypeScript 4.2.3

Looks like VSCode gives us all the @deprecated annotations, even though Ctrl + Clicking the method takes us to the correct signature :

image

@ebastuart
Copy link

Same issue here:
no matter if I use
.subscribe((value) => { /* code */ });
or
.subscribe({next: (value) => { /* code */ }}):

looking forward for a fix. thank

@orta
Copy link
Contributor

orta commented Mar 9, 2021

Hi folks, I'm not 100% that this is a TypeScript issue but an issue in both tslint and eslint which maybe aren't checking whether the used version of a function is deprecated.

When you make a blank project with:

mkdir 43053
yarn init -y
yarn add typescript rxjs
touch index.ts
code . 

Then open the file:

Screen Shot 2021-03-09 at 3 09 34 PM

We don't report to vscode that the former example is deprecated, which is what would happen if TypeScript thought it was deprecated.

--

That said, there's a reasonable possibility that the underlaying deprecations API usage which tslint and eslint may be using could have changed in 4.2 though which might have caused this, which I'll be looking into next

@wnabil
Copy link

wnabil commented Mar 9, 2021

Thank god I thought I need to update the subscriptions to a new syntax ...

@VhMuzini
Copy link

VhMuzini commented Mar 9, 2021

I think we should open a issue on Eslint since tslint is now deprecated

@orta
Copy link
Contributor

orta commented Mar 9, 2021

So far, I've narrowed it down to being a change in the returned values from getJsDocTags and getResolvedSignature.

With this script:

import * as ts from "typescript";

// Loop through the AST to find call expressions:
function traverse(sourceFile: ts.SourceFile) {
  lookAtNode(sourceFile);

  function lookAtNode(node: ts.Node) {
    if (ts.isCallExpression(node)) {
      check(node)
    }

    ts.forEachChild(node, lookAtNode);
  }
}

// Setup TypeScript environment
let program = ts.createProgram(["index.ts"], {});
let checker = program.getTypeChecker();
const sourceFile = program.getSourceFile("index.ts")!
traverse(sourceFile);

// Look at call expressions to see if they're deprecated based on code in tslint and SonarJS
function check(callExpression: ts.CallExpression) {
  const tc = checker;
  console.log("\n\nLooking at: ", callExpression.getText())

  const signature = tc.getResolvedSignature(callExpression);
  if (signature) {
    const tags = signature.getJsDocTags()
    const deprecated = tags.find(t => t.name === "deprecated")

    if (deprecated) {
      console.log("Deprecation from `getJsDocTags`", deprecated)
    }
  }
}

In 4.1:

Looking at:  somethingHappened.asObservable()


Looking at:  somethingHappened$.subscribe(() => {
  console.log('something happened');
})


Looking at:  console.log('something happened')


Looking at:  somethingHappened$.subscribe(null, undefined, () => {})
Deprecation from `getJsDocTags` {
  name: 'deprecated',
  text: 'Use an observer instead of a complete callback'
}

In 4.2:


Looking at:  somethingHappened.asObservable()


Looking at:  somethingHappened$.subscribe(() => {
  console.log('something happened');
})
Deprecation from `getJsDocTags` {
  name: 'deprecated',
  text: 'Use an observer instead of a complete callback'
}


Looking at:  console.log('something happened')


Looking at:  somethingHappened$.subscribe(null, undefined, () => {})
Deprecation from `getJsDocTags` {
  name: 'deprecated',
  text: 'Use an observer instead of a complete callback'
}


Looking at:  somethingHappened.next()

It's unlikely this output is what we want, so hold off on new issues for other projects.

@Julien-Marcou
Copy link
Author

Julien-Marcou commented Mar 9, 2021

Yes, I was about to say, even though VSCode no longer reports a deprecation warning after disabling TSLint & ESLint, changing between TypeScript 4.1.5 & 4.2.2 changes the content of the "documention popup" when hovering the subscribe method.

Documention popup with TypeScript 4.1.5 :
image

Documention popup with TypeScript 4.2.2 :
image

Also, ESLint has no dependency on TypeScript, so it would be more likely be related to the eslint-plugin-deprecation which has been made based on SonarJS (in addition I just saw that an issue has been opened about TypeScript 4.2 support for SonarJS which may be related to the deprecation warnings we are seeing)

@orta
Copy link
Contributor

orta commented Mar 9, 2021

OK, this looks like is an un-expected side-effect of #42098

Repro'd without the whole rxjs pipeline:

interface PartialObserver<T> {}
interface Subscription {}
interface Unsubscribable {}

export interface Subscribable<T> {
  subscribe(observer?: PartialObserver<T>): Unsubscribable;
  /** @deprecated 1 Use an observer instead of a complete callback */
  subscribe(next: null | undefined, error: null | undefined, complete: () => void): Unsubscribable;
  /** @deprecated 2 Use an observer instead of an error callback */
  subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Unsubscribable;
  /** @deprecated 3 Use an observer instead of a complete callback */
  subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Unsubscribable;
  subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Unsubscribable;
}

interface ThingWithDeprecations<T> extends Subscribable<T> {
    subscribe(observer?: PartialObserver<T>): Subscription;
    /** @deprecated Use an observer instead of a complete callback */
    subscribe(next: null | undefined, error: null | undefined, complete: () => void): Subscription;
    /** @deprecated Use an observer instead of an error callback */
    subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Subscription;
    /** @deprecated Use an observer instead of a complete callback */
    subscribe(next: (value: T) => void, error: null | undefined, complete: () => void): Subscription;
    subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
}

declare const a: ThingWithDeprecations<void>

// Fails with the above script
a.subscribe(() => {
  console.log('something happened');
});

The deprecations which are returned come from Subscribable not ThingWithDeprecations

@ubugnu
Copy link

ubugnu commented Mar 9, 2021

Same here, happened after updating to vscode 1.54.1

@fromage9747
Copy link

fromage9747 commented Mar 16, 2021

I am still getting this issue. Typescript 4.2.3, VScode 1.54.3 running on macOS Catalina. It also started happening after updating to VScode 1.54.1

@mhamri
Copy link

mhamri commented Mar 18, 2021

+1

@mhamri
Copy link

mhamri commented Mar 18, 2021

@sandersn can we open this issue? It come back again.

@Julien-Marcou
Copy link
Author

Actually, it never disappeared ^^

The fix has not been merged for the 4.2.X branch yet, it has only been merged for the next 4.3.X release.

You can track the merge progress for the 4.2.X branch here : #43180

@mhamri
Copy link

mhamri commented Mar 18, 2021

so why this issue is closed?

@anuragarwalkar
Copy link

facing same issue

@VincenzoLomba
Copy link

VincenzoLomba commented Mar 19, 2021

Same here, problem not solved yet (waiting for 4.3.X release).

@moscoso
Copy link

moscoso commented Mar 22, 2021

Facing same issue for Typescript 4.2.3

Vs Code versions:
Version: 1.54.2 (user setup)
Commit: fd6f3bce6709b121a895d042d343d71f317d74e7
Date: 2021-03-11T00:56:19.848Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.18363

@DrakeAnglin
Copy link

+1

1 similar comment
@Manu1909
Copy link

+1

@orta orta reopened this Mar 23, 2021
@orta
Copy link
Contributor

orta commented Mar 23, 2021

Re-opening until a 4.2 patch release, and brought up the request for a patch again 👍🏻

@1antares1
Copy link

Same here, problem not solved yet (waiting for 4.3.X release).

@adelynx
Copy link

adelynx commented Mar 26, 2021

Same issue here I have tried everything no chance.

@benjaminao
Copy link

Same issue here! Please let us know how avoid this warning!

@Julien-Marcou
Copy link
Author

If you really need TypeScript 4.2 -> Wait for a patch

If you don't need TypeScript 4.2 -> You can simply downgrade your project and VSCode to use TypeScript 4.1

  • Open a TypeScript file
  • Click on the current version of TypeScript you are using (bottom right corner of VSCode)
  • Choose "Select TypeScript Version..."
  • Choose "Use Workspace Version"

@orta
Copy link
Contributor

orta commented Mar 31, 2021

You can also use the nightly version of the TS extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next

@fromage9747
Copy link

Updated today to version 1.55 of VS code. The issue still persists.

@Julien-Marcou
Copy link
Author

TypeScript 4.2.4 has now been released, so we can close this.

A VSCode update should follow in about a week.

@mirzasetiyono
Copy link

have this issue solved?

@Julien-Marcou
Copy link
Author

Julien-Marcou commented Apr 18, 2021

Using this #43053 (comment) to force VScode to use TypeScript v4.2.4 instead of v4.2.3 I can confirm the issue has been fixed.

Unfortunately the branch for VSCode v1.55 still hasn't been updated with TypeScript v4.2.4.
I opened a request on the VSCode repository microsoft/vscode#121583 to get this fixed in VSCode 1.55.3 hopefully.

EDIT: Well, looks like we'll have to wait for VSCode v1.56 (scheduled for may), if we want to use the default TypeScript version of VSCode ^^

@my-lalex
Copy link

my-lalex commented Apr 30, 2021

My 2 cents, I'm not sure this is the right place to post this, but a deprecation warning still occurs on a specific situation.
Actually, it's in the 'body-parser' types of the Express plugin

/** @deprecated */
declare function bodyParser(
    options?: bodyParser.OptionsJson & bodyParser.OptionsText & bodyParser.OptionsUrlencoded,
): NextHandleFunction;

declare namespace bodyParser {
    //...
    /**
     * Returns middleware that only parses json and only looks at requests
     * where the Content-Type header matches the type option.
     */
    function json(options?: OptionsJson): NextHandleFunction;
    //...
}

Using bodyParser.json()in VSCode display the bodyParserpart as stroked (deprecated), and the json() part as it should (unstroked)...
The deprecation feature, in this case, doesn't understand that thebodyParserrefer to the namespace and not the function...

@fromage9747
Copy link

Today's update to VSCode sees it running Typescript 4.2.4 and the deprecation warning got Subscribe is no longer present!

@antoniobuttiglione
Copy link

Plus one here, I'm facing the same issue. The problem is that on RxJS website is not explained well how the new code should look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.