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

enable TS strict mode #10435

Closed
wants to merge 1 commit into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion configs/base.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"noEmitOnError": false,
"noImplicitThis": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"downlevelIteration": true,
Expand Down
12 changes: 6 additions & 6 deletions dev-packages/application-package/src/application-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import deepmerge = require('deepmerge');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ApplicationLog = (message?: any, ...optionalParams: any[]) => void;
export class ApplicationPackageOptions {
readonly projectPath: string;
readonly log?: ApplicationLog;
readonly error?: ApplicationLog;
readonly registry?: NpmRegistry;
readonly appTarget?: ApplicationProps.Target;
export interface ApplicationPackageOptions {
readonly projectPath: string
readonly log?: ApplicationLog
readonly error?: ApplicationLog
readonly registry?: NpmRegistry
readonly appTarget?: ApplicationProps.Target
}

export type ApplicationModuleResolver = (modulePath: string) => string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ExtensionPackageCollector {
protected readonly resolveModule: (modulePath: string) => string
) { }

protected root: NodePackage;
protected root?: NodePackage;
collect(pck: NodePackage): ReadonlyArray<ExtensionPackage> {
this.root = pck;
this.collectPackages(pck);
Expand Down Expand Up @@ -73,7 +73,7 @@ export class ExtensionPackageCollector {
if (RawExtensionPackage.is(pck)) {
const parent = this.parent;
const version = pck.version;
const transitive = !(name in this.root.dependencies!);
const transitive = !(name in this.root!.dependencies!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much do we gain if we mark it potentially undefined, and at the only mention that matters, simply assert that it isn't undefined?

Copy link
Member Author

@paul-marechal paul-marechal Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that if we had the strict checks enabled before, this method wouldn't have been implemented with this oddity in the first place. So not sure what to think about this code indeed. What I like right now is that it properly describes how root can be undefined but that this place expects it not to be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the rare case that this could become undefined in the future, I believe that having some sort of guard for that would be great. Something as simple as if (!this.root) { return; }

pck.installed = { packagePath, version, parent, transitive };
pck.version = versionRange;
const extensionPackage = this.extensionPackageFactory(pck, { alias: name });
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/application-package/src/npm-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class NpmRegistryOptions {
/**
* Default: false.
*/
readonly watchChanges: boolean;
readonly watchChanges: boolean = false;
}

export class NpmRegistry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ const FileWatchingPreferencesSchema: PreferenceSchema = {
@injectable()
class SampleFileWatchingContribution implements FrontendApplicationContribution {

protected verbose: boolean;
protected verbose: boolean = false;

@inject(FileService)
protected readonly fileService: FileService;
protected readonly fileService!: FileService;

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;
protected readonly labelProvider!: LabelProvider;

@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;
protected readonly workspaceService!: WorkspaceService;

@inject(FileWatchingPreferences)
protected readonly fileWatchingPreferences: FileWatchingPreferences;
protected readonly fileWatchingPreferences!: FileWatchingPreferences;

@postConstruct()
protected postConstruct(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export namespace ExampleLabelProviderCommands {
export class SampleDynamicLabelProviderCommandContribution implements FrontendApplicationContribution, CommandContribution {

@inject(SampleDynamicLabelProviderContribution)
protected readonly labelProviderContribution: SampleDynamicLabelProviderContribution;
protected readonly labelProviderContribution!: SampleDynamicLabelProviderContribution;

initialize(): void { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const SampleQuickInputCommand: Command = {
export class SampleCommandContribution implements CommandContribution {

@inject(QuickInputService)
protected readonly quickInputService: QuickInputService;
protected readonly quickInputService!: QuickInputService;

@inject(MessageService)
protected readonly messageService: MessageService;
protected readonly messageService!: MessageService;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(SampleCommand, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/b
export class SampleOutputChannelWithSeverity
implements FrontendApplicationContribution {
@inject(OutputChannelManager)
protected readonly outputChannelManager: OutputChannelManager;
protected readonly outputChannelManager!: OutputChannelManager;
public onStart(): void {
const channel = this.outputChannelManager.getChannel('API Sample: my test channel');
channel.appendLine('hello info1'); // showed without color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SampleUnclosableViewContribution extends AbstractViewContribution<S

protected toolbarItemState = false;

@inject(MessageService) protected readonly messageService: MessageService;
@inject(MessageService) protected readonly messageService!: MessageService;

constructor() {
super({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { Command, CommandContribution, CommandRegistry, MessageService } from '@
export class VSXCommandContribution implements CommandContribution {

@inject(MessageService)
protected readonly messageService: MessageService;
protected readonly messageService!: MessageService;

@inject(VSXEnvironment)
protected readonly environment: VSXEnvironment;
protected readonly environment!: VSXEnvironment;

protected readonly command: Command = {
id: 'vsx.echo-api-version',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class SampleUpdaterClientImpl implements SampleUpdaterClient {
export class ElectronMenuUpdater {

@inject(ElectronMainMenuFactory)
protected readonly factory: ElectronMainMenuFactory;
protected readonly factory!: ElectronMainMenuFactory;

public update(): void {
this.setMenu();
Expand All @@ -104,16 +104,16 @@ export class ElectronMenuUpdater {
export class SampleUpdaterFrontendContribution implements CommandContribution, MenuContribution {

@inject(MessageService)
protected readonly messageService: MessageService;
protected readonly messageService!: MessageService;

@inject(ElectronMenuUpdater)
protected readonly menuUpdater: ElectronMenuUpdater;
protected readonly menuUpdater!: ElectronMenuUpdater;

@inject(SampleUpdater)
protected readonly updater: SampleUpdater;
protected readonly updater!: SampleUpdater;

@inject(SampleUpdaterClientImpl)
protected readonly updaterClient: SampleUpdaterClientImpl;
protected readonly updaterClient!: SampleUpdaterClientImpl;

protected readyToUpdate = false;

Expand Down
4 changes: 2 additions & 2 deletions packages/bulk-edit/src/browser/bulk-edit-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import { nls } from '@theia/core/lib/common/nls';

@injectable()
export class BulkEditContribution extends AbstractViewContribution<BulkEditTreeWidget> implements TabBarToolbarContribution {
private edits: monaco.editor.ResourceEdit[];
private edits?: monaco.editor.ResourceEdit[];

@inject(QuickViewService) @optional()
protected readonly quickView: QuickViewService;
protected readonly quickView?: QuickViewService;

constructor(private readonly bulkEditService: MonacoBulkEditService) {
super({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { WorkspaceService } from '@theia/workspace/lib/browser';
export class BulkEditTreeLabelProvider implements LabelProviderContribution {

@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;
protected readonly labelProvider!: LabelProvider;

@inject(TreeLabelProvider)
protected readonly treeLabelProvider: TreeLabelProvider;
protected readonly treeLabelProvider!: TreeLabelProvider;

@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;
protected readonly workspaceService!: WorkspaceService;

canHandle(element: object): number {
return BulkEditInfoNode.is(element) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { TreeModelImpl, OpenerService, open, TreeNode } from '@theia/core/lib/br

@injectable()
export class BulkEditTreeModel extends TreeModelImpl {
@inject(BulkEditTree) protected readonly tree: BulkEditTree;
@inject(OpenerService) protected readonly openerService: OpenerService;
@inject(BulkEditTree) protected readonly tree!: BulkEditTree;
@inject(OpenerService) protected readonly openerService!: OpenerService;

protected doOpenNode(node: TreeNode): void {
if (BulkEditNode.is(node)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class BulkEditTreeWidget extends TreeWidget {
private editorWidgets: EditorWidget[] = [];

@inject(FileResourceResolver)
protected readonly fileResourceResolver: FileResourceResolver;
protected readonly fileResourceResolver!: FileResourceResolver;

@inject(EditorManager)
protected readonly editorManager: EditorManager;
protected readonly editorManager!: EditorManager;

@inject(QuickViewService) @optional()
protected readonly quickView: QuickViewService;
protected readonly quickView?: QuickViewService;

constructor(
@inject(TreeProps) readonly treeProps: TreeProps,
Expand Down Expand Up @@ -185,7 +185,7 @@ export class BulkEditTreeWidget extends TreeWidget {
let lines: string[] = [];
if (bulkEditInfoNode?.fileContents) {
lines = bulkEditInfoNode.fileContents.split('\n');
bulkEditInfoNode.children.map((node: BulkEditNode) => {
(bulkEditInfoNode.children as BulkEditNode[]).map(node => {
if (node.bulkEdit && ('textEdit' in node.bulkEdit)) {
const startLineNum = node.bulkEdit.textEdit.range.startLineNumber;
if (lines.length > startLineNum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class BulkEditTree extends TreeImpl {
bulkEditInfos = edits
.map(edit => this.getResourcePath(edit))
.filter((path, index, arr) => path && arr.indexOf(path) === index)
.map((path: string) => this.createBulkEditInfo(path, new URI(path), fileContentsMap.get(path)))
.map(path => this.createBulkEditInfo(path as string, new URI(path), fileContentsMap.get(path as string)))
.filter(Boolean);

if (bulkEditInfos.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export namespace CallHierarchyCommands {
@injectable()
export class CallHierarchyContribution extends AbstractViewContribution<CallHierarchyTreeWidget> {

@inject(CurrentEditorAccess) protected readonly editorAccess: CurrentEditorAccess;
@inject(CallHierarchyServiceProvider) protected readonly callHierarchyServiceProvider: CallHierarchyServiceProvider;
@inject(CurrentEditorAccess) protected readonly editorAccess!: CurrentEditorAccess;
@inject(CallHierarchyServiceProvider) protected readonly callHierarchyServiceProvider!: CallHierarchyServiceProvider;
constructor() {
super({
widgetId: CALLHIERARCHY_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface CallHierarchyService {
export class CallHierarchyServiceProvider {

@inject(ContributionProvider) @named(CallHierarchyService)
protected readonly contributions: ContributionProvider<CallHierarchyService>;
protected readonly contributions!: ContributionProvider<CallHierarchyService>;

private services: CallHierarchyService[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class CallHierarchyTreeModel extends TreeModelImpl {

private _languageId: string | undefined;

@inject(CallHierarchyTree) protected readonly tree: CallHierarchyTree;
@inject(CallHierarchyServiceProvider) protected readonly callHierarchyServiceProvider: CallHierarchyServiceProvider;
@inject(CallHierarchyTree) protected readonly tree!: CallHierarchyTree;
@inject(CallHierarchyServiceProvider) protected readonly callHierarchyServiceProvider!: CallHierarchyServiceProvider;

getTree(): CallHierarchyTree {
return this.tree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Location } from '@theia/core/shared/vscode-languageserver-types';
@injectable()
export class CurrentEditorAccess {

@inject(EditorManager) protected readonly editorManager: EditorManager;
@inject(EditorManager) protected readonly editorManager!: EditorManager;

getSelection(): Location | undefined {
const activeEditor = this.getCurrentEditor();
Expand Down
3 changes: 3 additions & 0 deletions packages/callhierarchy/src/common/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ function parsedExpression(expression: IExpression, options: IGlobOptions): Parse

if (!parsedPatterns.some(parsedPattern => (<ParsedExpressionPattern>parsedPattern).requiresSiblings!)) {
if (n === 1) {
// @ts-expect-error TS2322
return <ParsedStringPattern>parsedPatterns[0];
}

Expand Down Expand Up @@ -618,6 +619,7 @@ function parsedExpression(expression: IExpression, options: IGlobOptions): Parse
resultExpression.allPaths = allPaths;
}

// @ts-expect-error TS2322
return resultExpression;
}

Expand Down Expand Up @@ -655,6 +657,7 @@ function parsedExpression(expression: IExpression, options: IGlobOptions): Parse
resultExpression.allPaths = allPaths;
}

// @ts-expect-error TS2322
return resultExpression;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/browser/console-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export namespace ConsoleContextMenu {
export class ConsoleContribution implements FrontendApplicationContribution, CommandContribution, KeybindingContribution, MenuContribution {

@inject(ConsoleManager)
protected readonly manager: ConsoleManager;
protected readonly manager!: ConsoleManager;

initialize(): void { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ConsoleInputFocusContext implements KeybindingContext {
readonly id: string = ConsoleKeybindingContexts.consoleInputFocus;

@inject(ConsoleManager)
protected readonly manager: ConsoleManager;
protected readonly manager!: ConsoleManager;

isEnabled(): boolean {
const console = this.manager.activeConsole;
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/browser/console-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ConsoleWidget } from './console-widget';
export class ConsoleManager {

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;
protected readonly shell!: ApplicationShell;

get activeConsole(): ConsoleWidget | undefined {
const widget = this.shell.activeWidget;
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/browser/console-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class ConsoleSession extends TreeSource {
protected selectedSeverity?: Severity;
protected readonly selectionEmitter: Emitter<void> = new Emitter<void>();
readonly onSelectionChange = this.selectionEmitter.event;
id: string;
abstract id: string;

get severity(): Severity | undefined {
return this.selectedSeverity;
Expand Down
12 changes: 6 additions & 6 deletions packages/console/src/browser/console-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ export class ConsoleWidget extends BaseWidget implements StatefulWidget {
}

@inject(ConsoleOptions)
protected readonly options: ConsoleOptions;
protected readonly options!: ConsoleOptions;

@inject(ConsoleContentWidget)
readonly content: ConsoleContentWidget;
readonly content!: ConsoleContentWidget;

@inject(ConsoleHistory)
protected readonly history: ConsoleHistory;
protected readonly history!: ConsoleHistory;

@inject(ConsoleSessionManager)
protected readonly sessionManager: ConsoleSessionManager;
protected readonly sessionManager!: ConsoleSessionManager;

@inject(MonacoEditorProvider)
protected readonly editorProvider: MonacoEditorProvider;
protected readonly editorProvider!: MonacoEditorProvider;

protected _input: MonacoEditor;
protected _input!: MonacoEditor;

constructor() {
super();
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/browser/about-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ export const ABOUT_CONTENT_CLASS = 'theia-aboutDialog';
export const ABOUT_EXTENSIONS_CLASS = 'theia-aboutExtensions';

@injectable()
export class AboutDialogProps extends DialogProps {
export abstract class AboutDialogProps extends DialogProps {
}

@injectable()
export class AboutDialog extends ReactDialog<void> {
protected applicationInfo: ApplicationInfo | undefined;
protected applicationInfo?: ApplicationInfo;
protected extensionsInfos: ExtensionInfo[] = [];
protected readonly okButton: HTMLButtonElement;

@inject(ApplicationServer)
protected readonly appServer: ApplicationServer;
protected readonly appServer!: ApplicationServer;

constructor(
@inject(AboutDialogProps) protected readonly props: AboutDialogProps
Expand Down
Loading