Skip to content

Fix all typescript errors when compiled in strict mode #2 #4411

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

Merged
merged 5 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/611.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix all typescript errors when compiled in strict mode
4 changes: 2 additions & 2 deletions src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
const activatedWkspcFoldersRemoved = activatedWkspcKeys.filter(item => workspaceKeys.indexOf(item) < 0);
if (activatedWkspcFoldersRemoved.length > 0) {
for (const folder of activatedWkspcFoldersRemoved) {
this.lsActivatedWorkspaces.get(folder).dispose();
this.lsActivatedWorkspaces.delete(folder);
this.lsActivatedWorkspaces.get(folder)!.dispose();
this.lsActivatedWorkspaces!.delete(folder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class LanguageServerExtension implements ILanguageServerExtension {
this.disposable.dispose();
}
}
public register(): Promise<void> {
public async register(): Promise<void> {
if (this.disposable) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
} from 'vscode';
import * as vsls from 'vsls/vscode';

import { IAsyncDisposable } from '../types';
import { IAsyncDisposable, Resource } from '../types';

// tslint:disable:no-any unified-signatures

Expand Down Expand Up @@ -581,7 +581,7 @@ export interface IWorkspaceService {
* @param uri An uri.
* @return A workspace folder or `undefined`
*/
getWorkspaceFolder(uri: Uri): WorkspaceFolder | undefined;
getWorkspaceFolder(uri: Resource): WorkspaceFolder | undefined;

/**
* Generate a key that's unique to the workspace folder (could be fsPath).
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/variables/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function parseEnvFile(
baseVars?: EnvironmentVariables
): EnvironmentVariables {
const globalVars = baseVars ? baseVars : {};
const vars = {};
const vars : EnvironmentVariables = {};
lines.toString().split('\n').forEach((line, idx) => {
const [name, value] = parseEnvLine(line);
if (name === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/cellMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class CellMatcher {
}

public exec(code: string) : string | undefined {
let result: RegExpExecArray;
let result: RegExpExecArray | null = null;
if (this.codeMatchRegEx.test(code)) {
this.codeExecRegEx.lastIndex = -1;
result = this.codeExecRegEx.exec(code);
Expand Down
2 changes: 1 addition & 1 deletion src/client/datascience/historyMessageListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ export class HistoryMessageListener implements IWebPanelMessageListener {
}

private getHistoryMessages() : string [] {
return Object.keys(HistoryMessages).map(k => HistoryMessages[k].toString());
return Object.keys(HistoryMessages).map(k => (HistoryMessages as any)[k].toString());
}
}
2 changes: 1 addition & 1 deletion src/client/datascience/liveshare/postOffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class PostOffice implements IAsyncDisposable {
const jsonArray = JSON.parse(a.args) as JSONArray;
if (jsonArray !== null && jsonArray.length >= 2) {
const firstArg = jsonArray[0]; // More stupid hygiene problems.
const command = firstArg !== null ? firstArg.toString() : '';
const command = firstArg !== null ? firstArg!.toString() : '';
this.postCommand(command, ...jsonArray.slice(1)).ignoreErrors();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IDebugConfigurationResolver } from '../types';

@injectable()
export abstract class BaseConfigurationResolver<T extends DebugConfiguration> implements IDebugConfigurationResolver<T> {
protected pythonPathSource: PythonPathSource;
protected pythonPathSource: PythonPathSource = PythonPathSource.launchJson;
constructor(protected readonly workspaceService: IWorkspaceService,
protected readonly documentManager: IDocumentManager,
protected readonly configurationService: IConfigurationService) { }
Expand Down
2 changes: 1 addition & 1 deletion src/client/providers/jediProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class JediProxy implements Disposable {
}

private static getProperty<T>(o: object, name: string): T {
return <T>o[name];
return <T>(o as any)[name];
}

public dispose() {
Expand Down
3 changes: 2 additions & 1 deletion src/client/providers/symbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function flattenSymbolTree(tree: DocumentSymbol, uri: Uri, containerName: string
tree.name,
// Type coercion is a bit fuzzy when it comes to enums, so we
// play it safe by explicitly converting.
SymbolKind[SymbolKind[kind]],
// tslint:disable-next-line:no-any
(SymbolKind as any)[(SymbolKind as any)[kind]],
containerName,
new Location(uri, range)
);
Expand Down
4 changes: 2 additions & 2 deletions src/client/terminals/codeExecution/djangoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { IFileSystem } from '../../common/platform/types';
@injectable()
export class DjangoContextInitializer implements Disposable {
private readonly isDjangoProject: ContextKey;
private monitoringActiveTextEditor: boolean;
private monitoringActiveTextEditor: boolean = false;
private workspaceContextKeyValues = new Map<string, boolean>();
private lastCheckedWorkspace: string;
private lastCheckedWorkspace: string = '';
private disposables: Disposable[] = [];

constructor(private documentManager: IDocumentManager,
Expand Down
2 changes: 1 addition & 1 deletion src/client/typeFormatters/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class BlockRegEx {
constructor(private regEx: RegExp, public startWord) {
constructor(private regEx: RegExp, public startWord: String) {

}
public test(value: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestStatus } from '../types';
@injectable()
export class UnitTestDiagnosticService implements IUnitTestDiagnosticService {
private MessageTypes = new Map<TestStatus, DiagnosticMessageType>();
private MessageSeverities = new Map<PythonUnitTestMessageSeverity, DiagnosticSeverity>();
private MessageSeverities = new Map<PythonUnitTestMessageSeverity, DiagnosticSeverity | undefined>();
private MessagePrefixes = new Map<DiagnosticMessageType, string>();

constructor() {
Expand All @@ -23,16 +23,17 @@ export class UnitTestDiagnosticService implements IUnitTestDiagnosticService {
this.MessageSeverities.set(PythonUnitTestMessageSeverity.Error, DiagnosticSeverity.Error);
this.MessageSeverities.set(PythonUnitTestMessageSeverity.Failure, DiagnosticSeverity.Error);
this.MessageSeverities.set(PythonUnitTestMessageSeverity.Skip, DiagnosticSeverity.Information);
this.MessageSeverities.set(PythonUnitTestMessageSeverity.Pass, null);
this.MessageSeverities.set(PythonUnitTestMessageSeverity.Pass, undefined);
this.MessagePrefixes.set(DiagnosticMessageType.Error, localize.UnitTests.testErrorDiagnosticMessage());
this.MessagePrefixes.set(DiagnosticMessageType.Fail, localize.UnitTests.testFailDiagnosticMessage());
this.MessagePrefixes.set(DiagnosticMessageType.Skipped, localize.UnitTests.testSkippedDiagnosticMessage());
this.MessagePrefixes.set(DiagnosticMessageType.Pass, '');
}
public getMessagePrefix(status: TestStatus): string {
return this.MessagePrefixes.get(this.MessageTypes.get(status));
public getMessagePrefix(status: TestStatus): string | undefined {
const msgType = this.MessageTypes.get(status);
return msgType !== undefined ? this.MessagePrefixes.get(msgType!) : undefined;
}
public getSeverity(unitTestSeverity: PythonUnitTestMessageSeverity): DiagnosticSeverity {
public getSeverity(unitTestSeverity: PythonUnitTestMessageSeverity): DiagnosticSeverity | undefined {
return this.MessageSeverities.get(unitTestSeverity);
}
}
2 changes: 1 addition & 1 deletion src/client/unittests/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class UnitTestConfigurationService implements IUnitTestConfigurationServi
// tslint:disable-next-line:prefer-type-cast
return selectedTestRunner ? selectedTestRunner.product as UnitTestProduct : undefined;
}
public enableTest(wkspace: Uri, product: UnitTestProduct) {
public async enableTest(wkspace: Uri, product: UnitTestProduct): Promise<void> {
const factory = this.serviceContainer.get<ITestConfigurationManagerFactory>(ITestConfigurationManagerFactory);
const configMgr = factory.create(wkspace, product);
const pythonConfig = this.workspaceService.getConfiguration('python', wkspace);
Expand Down
8 changes: 4 additions & 4 deletions src/client/unittests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const IUnitTestConfigurationService = Symbol('IUnitTestConfigurationServi
export interface IUnitTestConfigurationService {
displayTestFrameworkError(wkspace: Uri): Promise<void>;
selectTestRunner(placeHolderMessage: string): Promise<UnitTestProduct | undefined>;
enableTest(wkspace: Uri, product: UnitTestProduct);
promptToEnableAndConfigureTestFramework(wkspace: Uri);
enableTest(wkspace: Uri, product: UnitTestProduct): Promise<void>;
promptToEnableAndConfigureTestFramework(wkspace: Uri): Promise<void>;
}

export const ITestResultDisplay = Symbol('ITestResultDisplay');
Expand Down Expand Up @@ -112,8 +112,8 @@ export interface IUnitTestHelper {

export const IUnitTestDiagnosticService = Symbol('IUnitTestDiagnosticService');
export interface IUnitTestDiagnosticService {
getMessagePrefix(status: TestStatus): string;
getSeverity(unitTestSeverity: PythonUnitTestMessageSeverity): DiagnosticSeverity;
getMessagePrefix(status: TestStatus): string | undefined;
getSeverity(unitTestSeverity: PythonUnitTestMessageSeverity): DiagnosticSeverity | undefined;
}

export interface IPythonUnitTestMessage {
Expand Down
11 changes: 6 additions & 5 deletions src/client/workspaceSymbols/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fsExistsAsync } from '../common/utils/fs';
import { Tag } from './contracts';

// tslint:disable:no-require-imports no-var-requires no-suspicious-comment
// tslint:disable:no-any
// TODO: Turn these into imports.
const LineByLineReader = require('line-by-line');
const NamedRegexp = require('named-js-regexp');
Expand All @@ -20,7 +21,7 @@ export interface IRegexGroup {
line: number;
}

export function matchNamedRegEx(data, regex): IRegexGroup | null {
export function matchNamedRegEx(data: String, regex: String): IRegexGroup | null {
const compiledRegexp = NamedRegexp(regex, 'g');
const rawMatch = compiledRegexp.exec(data);
if (rawMatch !== null) {
Expand Down Expand Up @@ -96,10 +97,10 @@ CTagKinMapping.set('_singleton methods', vscode.SymbolKind.Method);

const newValuesAndKeys = {};
CTagKinMapping.forEach((value, key) => {
newValuesAndKeys[key.substring(1)] = value;
(newValuesAndKeys as any)[key.substring(1)] = value;
});
Object.keys(newValuesAndKeys).forEach(key => {
CTagKinMapping.set(key, newValuesAndKeys[key]);
CTagKinMapping.set(key, (newValuesAndKeys as any)[key]);
});

export function parseTags(
Expand All @@ -119,11 +120,11 @@ export function parseTags(
let lineNumber = 0;
const tags: Tag[] = [];

lr.on('error', (err) => {
lr.on('error', (err: Error) => {
reject(err);
});

lr.on('line', (line) => {
lr.on('line', (line: string) => {
lineNumber = lineNumber + 1;
if (token.isCancellationRequested) {
lr.close();
Expand Down
9 changes: 4 additions & 5 deletions src/test/activation/activationService.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
LanguageServerActivator
} from '../../client/activation/types';
import { LSNotSupportedDiagnosticServiceId } from '../../client/application/diagnostics/checks/lsNotSupported';
import { IDiagnosticsService } from '../../client/application/diagnostics/types';
import { IDiagnostic, IDiagnosticsService } from '../../client/application/diagnostics/types';
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../client/common/application/types';
import { IPlatformService } from '../../client/common/platform/types';
import { IConfigurationService, IDisposable, IDisposableRegistry, IOutputChannel, IPythonSettings, Resource } from '../../client/common/types';
Expand Down Expand Up @@ -101,7 +101,7 @@ suite('Activation - ActivationService', () => {
if (lsSupported && !jediIsEnabled) {
activatorName = LanguageServerActivator.DotNet;
}
let diagnostics;
let diagnostics : IDiagnostic[];
if (!lsSupported && !jediIsEnabled) {
diagnostics = [TypeMoq.It.isAny()];
} else {
Expand Down Expand Up @@ -155,7 +155,6 @@ suite('Activation - ActivationService', () => {

activator
.setup(a => a.dispose())
.returns(() => Promise.resolve())
.verifiable(TypeMoq.Times.once());

activationService.dispose();
Expand Down Expand Up @@ -311,7 +310,7 @@ suite('Activation - ActivationService', () => {
const activatorDotNet = TypeMoq.Mock.ofType<ILanguageServerActivator>();
const activatorJedi = TypeMoq.Mock.ofType<ILanguageServerActivator>();
const activationService = new LanguageServerExtensionActivationService(serviceContainer.object);
const diagnostics = [];
const diagnostics: IDiagnostic[] = [];
lsNotSupportedDiagnosticService
.setup(l => l.diagnose(undefined))
.returns(() => Promise.resolve(diagnostics));
Expand Down Expand Up @@ -372,7 +371,7 @@ suite('Activation - ActivationService', () => {
.verifiable(TypeMoq.Times.atLeastOnce());
workspaceService
.setup(w => w.getWorkspaceFolderIdentifier(resource, ''))
.returns(() => resource.fsPath)
.returns(() => resource!.fsPath)
.verifiable(TypeMoq.Times.atLeastOnce());

await activationService.activate(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
test('Event Handler is registered and invoked', async () => {
let invoked = false;
let callbackHandler!: (e: ConfigurationChangeEvent) => Promise<void>;
const workspaceService = { onDidChangeConfiguration: cb => callbackHandler = cb } as any;
const workspaceService = { onDidChangeConfiguration: (cb : (e: ConfigurationChangeEvent) => Promise<void>) => callbackHandler = cb } as any;
const serviceContainerObject = createContainer();
serviceContainer.setup(s => s.get(typemoq.It.isValue(IWorkspaceService)))
.returns(() => workspaceService);
Expand Down Expand Up @@ -348,16 +348,16 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
serviceContainer.setup(s => s.get(typemoq.It.isValue(IWorkspaceService)))
.returns(() => workspaceService.object);
const diagnosticSvc = new class extends InvalidMacPythonInterpreterService {
constructor(arg1, arg2, arg3, arg4) {
constructor(arg1: IServiceContainer, arg2: IInterpreterService, arg3: IPlatformService, arg4: IInterpreterHelper) {
super(arg1, arg2, arg3, arg4);
this.changeThrottleTimeout = 1;
}
public onDidChangeConfigurationEx = e => super.onDidChangeConfiguration(e);
public onDidChangeConfigurationEx = (e: ConfigurationChangeEvent) => super.onDidChangeConfiguration(e);
public diagnose(): Promise<any> {
diagnoseInvocationCount += 1;
return Promise.resolve();
}
}(serviceContainerObject, undefined, undefined, undefined);
}(serviceContainerObject, typemoq.Mock.ofType<IInterpreterService>().object, typemoq.Mock.ofType<IPlatformService>().object, typemoq.Mock.ofType<IInterpreterHelper>().object);

event
.setup(e => e.affectsConfiguration(typemoq.It.isValue('python.pythonPath'), typemoq.It.isAny()))
Expand Down Expand Up @@ -389,16 +389,16 @@ suite('Application Diagnostics - Checks Python Interpreter', () => {
serviceContainer.setup(s => s.get(typemoq.It.isValue(IWorkspaceService)))
.returns(() => workspaceService.object);
const diagnosticSvc = new class extends InvalidMacPythonInterpreterService {
constructor(arg1, arg2, arg3, arg4) {
constructor(arg1: IServiceContainer, arg2: IInterpreterService, arg3: IPlatformService, arg4: IInterpreterHelper) {
super(arg1, arg2, arg3, arg4);
this.changeThrottleTimeout = 100;
}
public onDidChangeConfigurationEx = e => super.onDidChangeConfiguration(e);
public onDidChangeConfigurationEx = (e: ConfigurationChangeEvent) => super.onDidChangeConfiguration(e);
public diagnose(): Promise<any> {
diagnoseInvocationCount += 1;
return Promise.resolve();
}
}(serviceContainerObject, undefined, undefined, undefined);
}(serviceContainerObject, typemoq.Mock.ofType<IInterpreterService>().object, typemoq.Mock.ofType<IPlatformService>().object, typemoq.Mock.ofType<IInterpreterHelper>().object);

event
.setup(e => e.affectsConfiguration(typemoq.It.isValue('python.pythonPath'), typemoq.It.isAny()))
Expand Down