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

New Proposed API checking causes extensions to fail to load when using "import * as vscode" with TypeScript < 3.9 #111913

Closed
mwpenny opened this issue Dec 4, 2020 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release verified Verification succeeded
Milestone

Comments

@mwpenny
Copy link

mwpenny commented Dec 4, 2020

  • VSCode Version: 1.52.0-insiders (5e350b1)
  • OS Version: Windows 10 1809 (OS Build 17763.1518)

Steps to Reproduce:

  1. Create an extension (any sample will do) and use a TypeScript version below 3.9
  2. Somewhere in the extension, use import * as vscode from "vscode"
  3. Try to load the extension. It will fail with the "Proposed API is only available..." error

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

Note that this only happens on insiders.


Recent changes (c219b06) cause problems for extensions built with old versions of TypeScript (< 3.9). With these old versions

import * as vscode from "vscode"

gets emitted as:

var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];  // Problem
    result["default"] = mod;
    return result;
};

const vscode = __importStar(require("vscode"));

The line with my added "problem" comment will trigger some getters which include checkProposedApiEnabled() and cause the extension to fail to load with the "Proposed API is only available..." error even though it may never access the relevant properties. Later versions of TypeScript use a getter to defer property access and this isn't a problem.

Technically, I'd call this a TypeScript/tslib bug and not a VSCode bug. It's fixed in later versions of TypeScript (or worked around by changing the imports to import vscode from "vscode"), but I figured you'd like to be made aware since this could cause problems for a number of existing extensions.

@jrieken
Copy link
Member

jrieken commented Dec 9, 2020

@mwpenny Thanks for the detailed bug report. This is super helpful. What's has changed recently is that I added proposed-api checked for proposed types, e.g we have a new proposed class vscode.TimelineItem and accessing this new type is now also guarded by a proposed API usage check.

@jrieken jrieken added this to the November 2020 milestone Dec 9, 2020
@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release labels Dec 9, 2020
@jrieken
Copy link
Member

jrieken commented Dec 9, 2020

For the November release we should remove the checks for types again

@jrieken
Copy link
Member

jrieken commented Dec 9, 2020

I believe in addition to an old TS version <3.9 this also needs the following compiler option: "esModuleInterop": true. Without those two, I wasn't able to reproduce... @mwpenny Please confirm my finding.

Anyways, the following extension doesn't actually use proposed API but uses the bogous __importStar-utility and consequently fails to load: ts39-proposed-0.0.3.vsix.zip.

@jrieken
Copy link
Member

jrieken commented Dec 9, 2020

pushed to master and onto release/1.52

@jrieken jrieken closed this as completed Dec 9, 2020
@mwpenny
Copy link
Author

mwpenny commented Dec 9, 2020

@jrieken Thanks for the quick response. You're right that you also need "esModuleInterop": true. The project which alerted me to the problem has this compiler option set.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug candidate Issue identified as probable candidate for fixing in the next release verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants