From b743e245ad09b754699ae366fcf27ee50c477ddf Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 6 Nov 2017 11:38:30 -0800 Subject: [PATCH] Enable strict compilation settings in git extension Enables strict checks in the git extensions --- extensions/git/package.json | 1 + extensions/git/src/commands.ts | 6 +++--- extensions/git/src/decorators.ts | 8 ++++---- extensions/git/src/main.ts | 2 +- extensions/git/src/repository.ts | 4 ++-- extensions/git/src/util.ts | 10 +++++----- extensions/git/tsconfig.json | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 7b0b37af4c9..2366ee38aba 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -902,6 +902,7 @@ "devDependencies": { "@types/mocha": "2.2.43", "@types/node": "7.0.43", + "@types/byline": "4.2.31", "mocha": "^3.2.0" } } \ No newline at end of file diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 8350e133043..a175e67c860 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1384,7 +1384,7 @@ export class CommandCenter { } private createCommand(id: string, key: string, method: Function, options: CommandOptions): (...args: any[]) => any { - const result = (...args) => { + const result = (...args: any[]) => { let result: Promise; if (!options.repository) { @@ -1433,7 +1433,7 @@ export class CommandCenter { .replace(/^error: /mi, '') .replace(/^> husky.*$/mi, '') .split(/[\r\n]/) - .filter(line => !!line) + .filter((line: any) => !!line) [0]; message = hint @@ -1459,7 +1459,7 @@ export class CommandCenter { }; // patch this object, so people can call methods directly - this[key] = result; + (this as any)[key] = result; return result; } diff --git a/extensions/git/src/decorators.ts b/extensions/git/src/decorators.ts index 905d9e8501b..83ee04b17ad 100644 --- a/extensions/git/src/decorators.ts +++ b/extensions/git/src/decorators.ts @@ -31,7 +31,7 @@ function decorate(decorator: (fn: Function, key: string) => Function): Function function _memoize(fn: Function, key: string): Function { const memoizeKey = `$memoize$${key}`; - return function (...args: any[]) { + return function (this: any, ...args: any[]) { if (!this.hasOwnProperty(memoizeKey)) { Object.defineProperty(this, memoizeKey, { configurable: false, @@ -51,7 +51,7 @@ function _throttle(fn: Function, key: string): Function { const currentKey = `$throttle$current$${key}`; const nextKey = `$throttle$next$${key}`; - const trigger = function (...args: any[]) { + const trigger = function (this: any, ...args: any[]) { if (this[nextKey]) { return this[nextKey]; } @@ -81,7 +81,7 @@ export const throttle = decorate(_throttle); function _sequentialize(fn: Function, key: string): Function { const currentKey = `__$sequence$${key}`; - return function (...args: any[]) { + return function (this: any, ...args: any[]) { const currentPromise = this[currentKey] as Promise || Promise.resolve(null); const run = async () => await fn.apply(this, args); this[currentKey] = currentPromise.then(run, run); @@ -95,7 +95,7 @@ export function debounce(delay: number): Function { return decorate((fn, key) => { const timerKey = `$debounce$${key}`; - return function (...args: any[]) { + return function (this: any, ...args: any[]) { clearTimeout(this[timerKey]); this[timerKey] = setTimeout(() => fn.apply(this, args), delay); }; diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index b090495be71..bd9393ca52a 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -48,7 +48,7 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi outputChannel.appendLine(localize('using git', "Using git {0} from {1}", info.version, info.path)); - const onOutput = str => outputChannel.append(str); + const onOutput = (str: string) => outputChannel.append(str); git.onOutput.addListener('log', onOutput); disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput))); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index de7382190de..7086a9a4248 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -82,7 +82,7 @@ export class Resource implements SourceControlResourceState { get original(): Uri { return this._resourceUri; } get renameResourceUri(): Uri | undefined { return this._renameResourceUri; } - private static Icons = { + private static Icons: any = { light: { Modified: getIconUri('status-modified', 'light'), Added: getIconUri('status-added', 'light'), @@ -724,7 +724,7 @@ export class Repository implements Disposable { const child = this.repository.stream(['check-ignore', ...filePaths]); - const onExit = exitCode => { + const onExit = (exitCode: number) => { if (exitCode === 1) { // nothing ignored resolve(new Set()); diff --git a/extensions/git/src/util.ts b/extensions/git/src/util.ts index 6e1dc139340..9536cf44061 100644 --- a/extensions/git/src/util.ts +++ b/extensions/git/src/util.ts @@ -84,7 +84,7 @@ export function once(fn: (...args: any[]) => any): (...args: any[]) => any { }; } -export function assign(destination: T, ...sources: any[]): T { +export function assign(destination: T, ...sources: (keyof T)[]): T { for (const source of sources) { Object.keys(source).forEach(key => destination[key] = source[key]); } @@ -115,12 +115,12 @@ export function groupBy(arr: T[], fn: (el: T) => string): { [key: string]: T[ }, Object.create(null)); } -export function denodeify(fn: Function): (...args) => Promise { - return (...args) => new Promise((c, e) => fn(...args, (err, r) => err ? e(err) : c(r))); +export function denodeify(fn: Function): (...args: any[]) => Promise { + return (...args) => new Promise((c, e) => fn(...args, (err: any, r: any) => err ? e(err) : c(r))); } -export function nfcall(fn: Function, ...args): Promise { - return new Promise((c, e) => fn(...args, (err, r) => err ? e(err) : c(r))); +export function nfcall(fn: Function, ...args: any[]): Promise { + return new Promise((c, e) => fn(...args, (err: any, r: any) => err ? e(err) : c(r))); } export async function mkdirp(path: string, mode?: number): Promise { diff --git a/extensions/git/tsconfig.json b/extensions/git/tsconfig.json index 254c9e67459..085e5a2743c 100644 --- a/extensions/git/tsconfig.json +++ b/extensions/git/tsconfig.json @@ -6,7 +6,7 @@ ], "module": "commonjs", "outDir": "./out", - "strictNullChecks": true, + "strict": true, "experimentalDecorators": true }, "include": [