提交 46d8bb80 编写于 作者: M Matt Bierner

Strict null errors

#60656
上级 5527b1ee
......@@ -16,17 +16,22 @@
"./vs/base/browser/fastDomNode.ts",
"./vs/base/browser/globalMouseMoveMonitor.ts",
"./vs/base/browser/history.ts",
"./vs/base/browser/htmlContentRenderer.ts",
"./vs/base/browser/iframe.ts",
"./vs/base/browser/keyboardEvent.ts",
"./vs/base/browser/mouseEvent.ts",
"./vs/base/browser/touch.ts",
"./vs/base/browser/ui/aria/aria.ts",
"./vs/base/browser/ui/button/button.ts",
"./vs/base/browser/ui/contextview/contextview.ts",
"./vs/base/browser/ui/countBadge/countBadge.ts",
"./vs/base/browser/ui/keybindingLabel/keybindingLabel.ts",
"./vs/base/browser/ui/list/list.ts",
"./vs/base/browser/ui/list/splice.ts",
"./vs/base/browser/ui/octiconLabel/octiconLabel.mock.ts",
"./vs/base/browser/ui/octiconLabel/octiconLabel.ts",
"./vs/base/browser/ui/progressbar/progressbar.ts",
"./vs/base/browser/ui/sash/sash.ts",
"./vs/base/browser/ui/scrollbar/abstractScrollbar.ts",
"./vs/base/browser/ui/scrollbar/horizontalScrollbar.ts",
"./vs/base/browser/ui/scrollbar/scrollableElement.ts",
......@@ -35,6 +40,7 @@
"./vs/base/browser/ui/scrollbar/scrollbarState.ts",
"./vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts",
"./vs/base/browser/ui/scrollbar/verticalScrollbar.ts",
"./vs/base/browser/ui/splitview/splitview.ts",
"./vs/base/browser/ui/tree/tree.ts",
"./vs/base/browser/ui/widget.ts",
"./vs/base/node/decoder.ts",
......@@ -43,6 +49,7 @@
"./vs/base/node/ports.ts",
"./vs/base/node/request.ts",
"./vs/base/parts/contextmenu/common/contextmenu.ts",
"./vs/base/parts/contextmenu/electron-browser/contextmenu.ts",
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
"./vs/base/parts/ipc/node/ipc.ts",
"./vs/base/parts/ipc/test/node/testService.ts",
......@@ -330,7 +337,9 @@
"./vs/platform/instantiation/common/extensions.ts",
"./vs/platform/instantiation/common/graph.ts",
"./vs/platform/instantiation/common/instantiation.ts",
"./vs/platform/instantiation/common/instantiationService.ts",
"./vs/platform/instantiation/common/serviceCollection.ts",
"./vs/platform/instantiation/node/instantiationService.ts",
"./vs/platform/integrity/common/integrity.ts",
"./vs/platform/integrity/node/integrityServiceImpl.ts",
"./vs/platform/issue/common/issue.ts",
......@@ -405,6 +414,7 @@
"./vs/workbench/common/views.ts",
"./vs/workbench/parts/codeEditor/browser/menuPreventer.ts",
"./vs/workbench/parts/codeEditor/browser/simpleEditorOptions.ts",
"./vs/workbench/parts/codeEditor/electron-browser/accessibility.ts",
"./vs/workbench/parts/codeEditor/electron-browser/largeFileOptimizations.ts",
"./vs/workbench/parts/codeEditor/electron-browser/selectionClipboard.ts",
"./vs/workbench/parts/codeEditor/electron-browser/toggleWordWrap.ts",
......@@ -419,6 +429,7 @@
"./vs/workbench/parts/logs/common/logConstants.ts",
"./vs/workbench/parts/markers/electron-browser/constants.ts",
"./vs/workbench/parts/markers/electron-browser/markers.ts",
"./vs/workbench/parts/markers/electron-browser/markersFilterOptions.ts",
"./vs/workbench/parts/markers/electron-browser/markersModel.ts",
"./vs/workbench/parts/markers/electron-browser/messages.ts",
"./vs/workbench/parts/outline/electron-browser/outline.ts",
......
......@@ -67,8 +67,8 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
if (parameters) {
const heightFromParams = /height=(\d+)/.exec(parameters);
const widthFromParams = /width=(\d+)/.exec(parameters);
const height = (heightFromParams && heightFromParams[1]);
const width = (widthFromParams && widthFromParams[1]);
const height = heightFromParams ? heightFromParams[1] : '';
const width = widthFromParams ? widthFromParams[1] : '';
const widthIsFinite = isFinite(parseInt(width));
const heightIsFinite = isFinite(parseInt(height));
if (widthIsFinite) {
......@@ -120,7 +120,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
if (options.codeBlockRenderer) {
renderer.code = (code, lang) => {
const value = options.codeBlockRenderer(lang, code);
const value = options.codeBlockRenderer!(lang, code);
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
......@@ -144,7 +144,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
if (options.actionHandler) {
options.actionHandler.disposeables.push(DOM.addStandardDisposableListener(element, 'click', event => {
let target = event.target;
let target: HTMLElement | null = event.target;
if (target.tagName !== 'A') {
target = target.parentElement;
if (!target || target.tagName !== 'A') {
......@@ -154,7 +154,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
try {
const href = target.dataset['href'];
if (href) {
options.actionHandler.callback(href, event);
options.actionHandler!.callback(href, event);
}
} catch (err) {
onUnexpectedError(err);
......@@ -170,7 +170,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: RenderOptions
};
element.innerHTML = marked(markdown.value, markedOptions);
signalInnerHTML();
signalInnerHTML!();
return element;
}
......@@ -224,10 +224,10 @@ interface IFormatParseTree {
}
function _renderFormattedText(element: Node, treeNode: IFormatParseTree, actionHandler?: IContentActionHandler) {
let child: Node;
let child: Node | undefined;
if (treeNode.type === FormatType.Text) {
child = document.createTextNode(treeNode.content);
child = document.createTextNode(treeNode.content || '');
}
else if (treeNode.type === FormatType.Bold) {
child = document.createElement('b');
......@@ -251,13 +251,13 @@ function _renderFormattedText(element: Node, treeNode: IFormatParseTree, actionH
child = element;
}
if (element !== child) {
if (child && element !== child) {
element.appendChild(child);
}
if (Array.isArray(treeNode.children)) {
if (child && Array.isArray(treeNode.children)) {
treeNode.children.forEach((nodeChild) => {
_renderFormattedText(child, nodeChild, actionHandler);
_renderFormattedText(child!, nodeChild, actionHandler);
});
}
}
......@@ -286,12 +286,12 @@ function parseFormattedText(content: string): IFormatParseTree {
stream.advance();
if (current.type === FormatType.Text) {
current = stack.pop();
current = stack.pop()!;
}
const type = formatTagType(next);
if (current.type === type || (current.type === FormatType.Action && type === FormatType.ActionClose)) {
current = stack.pop();
current = stack.pop()!;
} else {
const newCurrent: IFormatParseTree = {
type: type,
......@@ -303,16 +303,16 @@ function parseFormattedText(content: string): IFormatParseTree {
actionItemIndex++;
}
current.children.push(newCurrent);
current.children!.push(newCurrent);
stack.push(current);
current = newCurrent;
}
} else if (next === '\n') {
if (current.type === FormatType.Text) {
current = stack.pop();
current = stack.pop()!;
}
current.children.push({
current.children!.push({
type: FormatType.NewLine
});
......@@ -322,7 +322,7 @@ function parseFormattedText(content: string): IFormatParseTree {
type: FormatType.Text,
content: next
};
current.children.push(textCurrent);
current.children!.push(textCurrent);
stack.push(current);
current = textCurrent;
......@@ -333,7 +333,7 @@ function parseFormattedText(content: string): IFormatParseTree {
}
if (current.type === FormatType.Text) {
current = stack.pop();
current = stack.pop()!;
}
if (stack.length) {
......
......@@ -35,10 +35,10 @@ export class Button extends Disposable {
private _element: HTMLElement;
private options: IButtonOptions;
private buttonBackground: Color;
private buttonHoverBackground: Color;
private buttonForeground: Color;
private buttonBorder: Color;
private buttonBackground: Color | undefined;
private buttonHoverBackground: Color | undefined;
private buttonForeground: Color | undefined;
private buttonBorder: Color | undefined;
private _onDidClick = this._register(new Emitter<any>());
get onDidClick(): BaseEvent<Event> { return this._onDidClick.event; }
......@@ -203,7 +203,7 @@ export class ButtonGroup extends Disposable {
let eventHandled = true;
// Next / Previous Button
let buttonIndexToFocus: number;
let buttonIndexToFocus: number | undefined;
if (event.equals(KeyCode.LeftArrow)) {
buttonIndexToFocus = index > 0 ? index - 1 : this._buttons.length - 1;
} else if (event.equals(KeyCode.RightArrow)) {
......@@ -212,7 +212,7 @@ export class ButtonGroup extends Disposable {
eventHandled = false;
}
if (eventHandled) {
if (eventHandled && typeof buttonIndexToFocus === 'number') {
this._buttons[buttonIndexToFocus].focus();
DOM.EventHelper.stop(e, true);
}
......
......@@ -33,9 +33,9 @@ export class CountBadge {
private countFormat: string;
private titleFormat: string;
private badgeBackground: Color;
private badgeForeground: Color;
private badgeBorder: Color;
private badgeBackground: Color | undefined;
private badgeForeground: Color | undefined;
private badgeBorder: Color | undefined;
private options: ICountBadgeOptions;
......
......@@ -62,10 +62,10 @@ export class KeybindingLabel implements IDisposable {
this.renderPart(this.domNode, firstPart, this.matches ? this.matches.firstPart : null);
}
if (chordPart) {
dom.append(this.domNode, $('span.monaco-keybinding-key-chord-separator', null, ' '));
dom.append(this.domNode, $('span.monaco-keybinding-key-chord-separator', undefined, ' '));
this.renderPart(this.domNode, chordPart, this.matches ? this.matches.chordPart : null);
}
this.domNode.title = this.keybinding.getAriaLabel();
this.domNode.title = this.keybinding.getAriaLabel() || '';
}
this.didEverRender = true;
......@@ -92,9 +92,9 @@ export class KeybindingLabel implements IDisposable {
}
private renderKey(parent: HTMLElement, label: string, highlight: boolean, separator: string): void {
dom.append(parent, $('span.monaco-keybinding-key' + (highlight ? '.highlight' : ''), null, label));
dom.append(parent, $('span.monaco-keybinding-key' + (highlight ? '.highlight' : ''), undefined, label));
if (separator) {
dom.append(parent, $('span.monaco-keybinding-key-separator', null, separator));
dom.append(parent, $('span.monaco-keybinding-key-separator', undefined, separator));
}
}
......
......@@ -391,6 +391,6 @@ export class Sash extends Disposable {
this.el.parentElement.removeChild(this.el);
}
this.el = null;
this.el = null!; // StrictNullOverride: nulling out ok in dispose
}
}
......@@ -13,7 +13,12 @@ export function popup(items: IContextMenuItem[], options?: IPopupOptions): void
const contextMenuId = contextMenuIdPool++;
const onClickChannel = `vscode:onContextMenu${contextMenuId}`;
const onClickChannelHandler = (_event: Event, itemId: number, context: IContextMenuEvent) => processedItems[itemId].click(context);
const onClickChannelHandler = (_event: Event, itemId: number, context: IContextMenuEvent) => {
const item = processedItems[itemId];
if (item.click) {
item.click(context);
}
};
ipcRenderer.once(onClickChannel, onClickChannelHandler);
ipcRenderer.once(CONTEXT_MENU_CLOSE_CHANNEL, (_event: Event, closedContextMenuId: number) => {
......
......@@ -42,7 +42,7 @@ export class CompositeSnippetVariableResolver implements VariableResolver {
//
}
resolve(variable: Variable): string {
resolve(variable: Variable): string | undefined {
for (const delegate of this._delegates) {
let value = delegate.resolve(variable);
if (value !== void 0) {
......@@ -62,7 +62,7 @@ export class SelectionBasedVariableResolver implements VariableResolver {
//
}
resolve(variable: Variable): string {
resolve(variable: Variable): string | undefined {
const { name } = variable;
......@@ -124,7 +124,7 @@ export class ModelBasedVariableResolver implements VariableResolver {
//
}
resolve(variable: Variable): string {
resolve(variable: Variable): string | undefined {
const { name } = variable;
......@@ -162,7 +162,7 @@ export class ClipboardBasedVariableResolver implements VariableResolver {
//
}
resolve(variable: Variable): string {
resolve(variable: Variable): string | undefined {
if (variable.name !== 'CLIPBOARD' || !this._clipboardService) {
return undefined;
}
......@@ -188,7 +188,7 @@ export class TimeBasedVariableResolver implements VariableResolver {
private static readonly monthNames = [nls.localize('January', "January"), nls.localize('February', "February"), nls.localize('March', "March"), nls.localize('April', "April"), nls.localize('May', "May"), nls.localize('June', "June"), nls.localize('July', "July"), nls.localize('August', "August"), nls.localize('September', "September"), nls.localize('October', "October"), nls.localize('November', "November"), nls.localize('December', "December")];
private static readonly monthNamesShort = [nls.localize('JanuaryShort', "Jan"), nls.localize('FebruaryShort', "Feb"), nls.localize('MarchShort', "Mar"), nls.localize('AprilShort', "Apr"), nls.localize('MayShort', "May"), nls.localize('JuneShort', "Jun"), nls.localize('JulyShort', "Jul"), nls.localize('AugustShort', "Aug"), nls.localize('SeptemberShort', "Sep"), nls.localize('OctoberShort', "Oct"), nls.localize('NovemberShort', "Nov"), nls.localize('DecemberShort', "Dec")];
resolve(variable: Variable): string {
resolve(variable: Variable): string | undefined {
const { name } = variable;
if (name === 'CURRENT_YEAR') {
......
......@@ -19,7 +19,7 @@ export class InstantiationService implements IInstantiationService {
protected readonly _services: ServiceCollection;
protected readonly _strict: boolean;
protected readonly _parent: InstantiationService;
protected readonly _parent?: InstantiationService;
constructor(services: ServiceCollection = new ServiceCollection(), strict: boolean = false, parent?: InstantiationService) {
this._services = services;
......@@ -146,7 +146,7 @@ export class InstantiationService implements IInstantiationService {
let count = 0;
const stack = [{ id, desc, _trace }];
while (stack.length) {
const item = stack.pop();
const item = stack.pop()!;
graph.lookupOrInsertNode(item);
// TODO@joh use the graph to find a cycle
......@@ -198,8 +198,10 @@ export class InstantiationService implements IInstantiationService {
private _createServiceInstanceWithOwner<T>(id: ServiceIdentifier<T>, ctor: any, args: any[] = [], _trace: Trace): T {
if (this._services.get(id) instanceof SyncDescriptor) {
return this._createServiceInstance(ctor, args, _trace);
} else {
} else if (this._parent) {
return this._parent._createServiceInstanceWithOwner(id, ctor, args, _trace);
} else {
throw new Error('illegalState - creating UNKNOWN service instance');
}
}
......@@ -236,7 +238,7 @@ class Trace {
private constructor(
readonly type: TraceType,
readonly name: string
readonly name: string | null
) { }
branch(id: ServiceIdentifier<any>, first: boolean): Trace {
......@@ -255,7 +257,7 @@ class Trace {
let res: string[] = [];
let prefix = new Array(n + 1).join('\t');
for (const [id, first, child] of trace._dep) {
if (first) {
if (first && child) {
causedCreation = true;
res.push(`${prefix}CREATES -> ${id}`);
let nested = printChild(n + 1, child);
......
......@@ -16,8 +16,8 @@ export class FilterOptions {
readonly filterErrors: boolean = false;
readonly filterWarnings: boolean = false;
readonly filterInfos: boolean = false;
readonly excludePattern: ParsedExpression = null;
readonly includePattern: ParsedExpression = null;
readonly excludePattern: ParsedExpression | null = null;
readonly includePattern: ParsedExpression | null = null;
readonly textFilter: string = '';
constructor(readonly filter: string = '', excludePatterns: IExpression = {}) {
......@@ -61,7 +61,7 @@ export class FilterOptions {
}
private matches(prefix: string, word: string): boolean {
let result = matchesPrefix(prefix, word);
return result && result.length > 0;
const result = matchesPrefix(prefix, word);
return !!(result && result.length > 0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册