Fix VSCode/Extensions for TS 2.3.1 (#25248)

From: https://github.com/Microsoft/TypeScript/issues/15352

TS 2.3.1 introduced a breaking change around checking of generic types. This change tries to fix these compiler errors in the extensions codebase
This commit is contained in:
Matt Bierner 2017-04-24 16:05:57 -07:00 committed by GitHub
parent fbfb925b4d
commit dc0f3ecdb2
8 changed files with 16 additions and 14 deletions

View file

@ -20,7 +20,7 @@ export class Askpass implements Disposable {
try { try {
this.server.listen(0); this.server.listen(0);
this.portPromise = new Promise(c => this.server.on('listening', () => c(this.server.address().port))); this.portPromise = new Promise<number>(c => this.server.on('listening', () => c(this.server.address().port)));
this.server.on('error', err => console.error(err)); this.server.on('error', err => console.error(err));
} catch (err) { } catch (err) {
this.enabled = false; this.enabled = false;

View file

@ -533,7 +533,7 @@ export class CommandCenter {
} }
private async smartCommit( private async smartCommit(
getCommitMessage: () => Promise<string>, getCommitMessage: () => Promise<string | undefined>,
opts?: CommitOptions opts?: CommitOptions
): Promise<boolean> { ): Promise<boolean> {
if (!opts) { if (!opts) {

View file

@ -68,7 +68,7 @@ export function once<T>(event: Event<T>): Event<T> {
} }
export function eventToPromise<T>(event: Event<T>): Promise<T> { export function eventToPromise<T>(event: Event<T>): Promise<T> {
return new Promise(c => once(event)(c)); return new Promise<T>(c => once(event)(c));
} }
// TODO@Joao: replace with Object.assign // TODO@Joao: replace with Object.assign
@ -104,11 +104,11 @@ export function groupBy<T>(arr: T[], fn: (el: T) => string): { [key: string]: T[
} }
export function denodeify<R>(fn: Function): (...args) => Promise<R> { export function denodeify<R>(fn: Function): (...args) => Promise<R> {
return (...args) => new Promise((c, e) => fn(...args, (err, r) => err ? e(err) : c(r))); return (...args) => new Promise<R>((c, e) => fn(...args, (err, r) => err ? e(err) : c(r)));
} }
export function nfcall<R>(fn: Function, ...args): Promise<R> { export function nfcall<R>(fn: Function, ...args): Promise<R> {
return new Promise((c, e) => fn(...args, (err, r) => err ? e(err) : c(r))); return new Promise<R>((c, e) => fn(...args, (err, r) => err ? e(err) : c(r)));
} }
export async function mkdirp(path: string, mode?: number): Promise<boolean> { export async function mkdirp(path: string, mode?: number): Promise<boolean> {

View file

@ -176,7 +176,7 @@ export class ThrottledDelayer<T> extends Delayer<Promise<T>> {
constructor(defaultDelay: number) { constructor(defaultDelay: number) {
super(defaultDelay); super(defaultDelay);
this.throttler = new Throttler(); this.throttler = new Throttler<T>();
} }
public trigger(promiseFactory: ITask<Promise<T>>, delay?: number): Promise<Promise<T>> { public trigger(promiseFactory: ITask<Promise<T>>, delay?: number): Promise<Promise<T>> {

View file

@ -117,13 +117,15 @@ export default class TypeScriptFormattingProvider implements DocumentRangeFormat
if (!absPath) { if (!absPath) {
return Promise.resolve(Object.create(null)); return Promise.resolve(Object.create(null));
} }
const formatOptions = this.getFormatOptions(options);
const args: Proto.ConfigureRequestArguments = { const args: Proto.ConfigureRequestArguments = {
file: absPath, file: absPath,
formatOptions: this.getFormatOptions(options) formatOptions: formatOptions
}; };
return this.client.execute('configure', args, token).then(_ => { return this.client.execute('configure', args, token).then(_ => {
this.formatOptions[key] = args.formatOptions; this.formatOptions[key] = formatOptions;
return args.formatOptions; return formatOptions;
}); });
} }
} }

View file

@ -123,7 +123,7 @@ export function activate(context: ExtensionContext): void {
window.onDidChangeActiveTextEditor(VersionStatus.showHideStatus, null, context.subscriptions); window.onDidChangeActiveTextEditor(VersionStatus.showHideStatus, null, context.subscriptions);
client.onReady().then(() => { client.onReady().then(() => {
context.subscriptions.push(ProjectStatus.create(client, context.subscriptions.push(ProjectStatus.create(client,
path => new Promise(resolve => setTimeout(() => resolve(clientHost.handles(path)), 750)), path => new Promise<boolean>(resolve => setTimeout(() => resolve(clientHost.handles(path)), 750)),
context.workspaceState)); context.workspaceState));
}, () => { }, () => {
// Nothing to do here. The client did show a message; // Nothing to do here. The client did show a message;

View file

@ -686,7 +686,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if (localModulePath) { if (localModulePath) {
tryShowRestart(localModulePath); tryShowRestart(localModulePath);
} }
return localModulePath; return localModulePath || '';
}); });
case MessageAction.useBundled: case MessageAction.useBundled:
return this.workspaceState.update(TypeScriptServiceClient.useWorkspaceTsdkStorageKey, false) return this.workspaceState.update(TypeScriptServiceClient.useWorkspaceTsdkStorageKey, false)

View file

@ -13,7 +13,7 @@ export class Delayer<T> {
public defaultDelay: number; public defaultDelay: number;
private timeout: any; // Timer private timeout: any; // Timer
private completionPromise: Promise<T> | null; private completionPromise: Promise<T | null> | null;
private onSuccess: ((value?: T | Thenable<T>) => void) | null; private onSuccess: ((value?: T | Thenable<T>) => void) | null;
private task: ITask<T> | null; private task: ITask<T> | null;
@ -25,7 +25,7 @@ export class Delayer<T> {
this.task = null; this.task = null;
} }
public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T> { public trigger(task: ITask<T>, delay: number = this.defaultDelay): Promise<T | null> {
this.task = task; this.task = task;
if (delay >= 0) { if (delay >= 0) {
this.cancelTimeout(); this.cancelTimeout();
@ -55,7 +55,7 @@ export class Delayer<T> {
return this.completionPromise; return this.completionPromise;
} }
public forceDelivery(): Promise<T> | null { public forceDelivery(): Promise<T | null> | null {
if (!this.completionPromise) { if (!this.completionPromise) {
return null; return null;
} }