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

Strict nulls for everything except logconsole #7657

Merged
merged 16 commits into from Dec 23, 2019
4 changes: 2 additions & 2 deletions packages/cells/src/widget.ts
Expand Up @@ -251,7 +251,7 @@ export class Cell extends Widget {
if (!this._inputHidden) {
return this._input.promptNode;
} else {
return (this._inputPlaceholder.node as HTMLElement)
return (this._inputPlaceholder!.node as HTMLElement)
.firstElementChild as HTMLElement;
}
}
Expand Down Expand Up @@ -924,7 +924,7 @@ export class CodeCell extends Cell {
*/
cloneOutputArea(): OutputArea {
return new SimplifiedOutputArea({
model: this.model.outputs,
model: this.model.outputs!,
contentFactory: this.contentFactory,
rendermime: this._rendermime
});
Expand Down
10 changes: 5 additions & 5 deletions packages/console/src/widget.ts
Expand Up @@ -464,11 +464,11 @@ export class CodeConsole extends Widget {
clientX: number,
clientY: number
): Promise<void> {
const cellModel = this._focusedCell.model as ICodeCellModel;
const cellModel = this._focusedCell!.model as ICodeCellModel;
let selected: nbformat.ICell[] = [cellModel.toJSON()];

const dragImage = CellDragUtils.createCellDragImage(
this._focusedCell,
this._focusedCell!,
selected
);

Expand Down Expand Up @@ -690,10 +690,10 @@ export class CodeConsole extends Widget {
*/
private _handleInfo(info: KernelMessage.IInfoReplyMsg['content']): void {
if (info.status !== 'ok') {
this._banner.model.value.text = 'Error in getting kernel banner';
this._banner!.model.value.text = 'Error in getting kernel banner';
return;
}
this._banner.model.value.text = info.banner;
this._banner!.model.value.text = info.banner;
let lang = info.language_info as nbformat.ILanguageInfoMetadata;
this._mimetype = this._mimeTypeService.getMimeTypeByLanguage(lang);
if (this.promptCell) {
Expand Down Expand Up @@ -806,7 +806,7 @@ export class CodeConsole extends Widget {
});
} else if (this.session.status === 'restarting') {
this.addBanner();
this._handleInfo(this.session.kernel.info);
this._handleInfo(this.session.kernel!.info!);
}
}

Expand Down
24 changes: 12 additions & 12 deletions packages/csvviewer/src/model.ts
Expand Up @@ -83,9 +83,9 @@ export class DSVModel extends DataModel implements IDisposable {
this._parseAsync();

// Cache the header row.
if (header === true && this._columnCount > 0) {
if (header === true && this._columnCount! > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

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

It was really hard to track down when the various variables in the CSV viewer code was null/undefined, so for now I simply added non-null asserts everywhere. This commit has a lot of other such asserts as well, and basically maintains the status-quo, even if they might have revealed some incorrect nullable handling. The main point to review this for is if any fix of an incorrect call here would cause an API breakage (we could probably put those as "fixing" typings as a bug, so might be ok).

let h = [];
for (let c = 0; c < this._columnCount; c++) {
for (let c = 0; c < this._columnCount!; c++) {
h.push(this._getField(0, c));
}
this._header = h;
Expand Down Expand Up @@ -116,9 +116,9 @@ export class DSVModel extends DataModel implements IDisposable {
rowCount(region: DataModel.RowRegion): number {
if (region === 'body') {
if (this._header.length === 0) {
return this._rowCount;
return this._rowCount!;
} else {
return this._rowCount - 1;
return this._rowCount! - 1;
}
}
return 1;
Expand All @@ -133,7 +133,7 @@ export class DSVModel extends DataModel implements IDisposable {
*/
columnCount(region: DataModel.ColumnRegion): number {
if (region === 'body') {
return this._columnCount;
return this._columnCount!;
}
return 1;
}
Expand Down Expand Up @@ -226,7 +226,7 @@ export class DSVModel extends DataModel implements IDisposable {
private _computeRowOffsets(endRow = 4294967295): void {
// If we've already parsed up to endRow, or if we've already parsed the
// entire data set, return early.
if (this._rowCount >= endRow || this._doneParsing === true) {
if (this._rowCount! >= endRow || this._doneParsing === true) {
return;
}

Expand All @@ -247,12 +247,12 @@ export class DSVModel extends DataModel implements IDisposable {
// last row offset we have.
let { nrows, offsets } = PARSERS[this._parser]({
data: this._data,
startIndex: this._rowOffsets[this._rowCount - 1],
startIndex: this._rowOffsets[this._rowCount! - 1],
delimiter: this._delimiter,
rowDelimiter: this._rowDelimiter,
quote: this._quote,
columnOffsets: false,
maxRows: endRow - this._rowCount + 1
maxRows: endRow - this._rowCount! + 1
});

// Return if we didn't actually get any new rows beyond the one we've
Expand All @@ -266,7 +266,7 @@ export class DSVModel extends DataModel implements IDisposable {
this._startedParsing = true;

// Update the row count.
let oldRowCount = this._rowCount;
let oldRowCount = this._rowCount!;
this._rowCount = oldRowCount + nrows - 1;

// If we didn't reach the requested row, we must be done.
Expand Down Expand Up @@ -356,9 +356,9 @@ export class DSVModel extends DataModel implements IDisposable {
// Find the end of the slice (the start of the next field), and how much we
// should adjust to trim off a trailing field or row delimiter. First check
// if we are getting the last column.
if (column === this._columnCount - 1) {
if (column === this._columnCount! - 1) {
// Check if we are getting any row but the last.
if (row < this._rowCount - 1) {
if (row < this._rowCount! - 1) {
// Set the next offset to the next row, column 0.
nextIndex = this._getOffsetIndex(row + 1, 0);

Expand Down Expand Up @@ -417,7 +417,7 @@ export class DSVModel extends DataModel implements IDisposable {
*/
private _getOffsetIndex(row: number, column: number): number {
// Declare local variables.
const ncols = this._columnCount;
const ncols = this._columnCount!;

// Check to see if row *should* be in the cache, based on the cache size.
let rowIndex = (row - this._columnOffsetsStartingRow) * ncols;
Expand Down
6 changes: 3 additions & 3 deletions packages/csvviewer/src/widget.ts
Expand Up @@ -124,7 +124,7 @@ export class GridSearchService {
* incrementally look for searchText.
*/
find(query: RegExp, reverse = false): boolean {
const model = this._grid.dataModel;
const model = this._grid.dataModel!;
const rowCount = model.rowCount('body');
const columnCount = model.columnCount('body');

Expand Down Expand Up @@ -205,7 +205,7 @@ export class GridSearchService {
* Wrap indices if needed to just before the start or just after the end.
*/
private _wrapRows(reverse = false) {
const model = this._grid.dataModel;
const model = this._grid.dataModel!;
const rowCount = model.rowCount('body');
const columnCount = model.columnCount('body');

Expand Down Expand Up @@ -441,7 +441,7 @@ export class CSVDocumentWidget extends DocumentWidget<CSVViewer> {
this.toolbar.addItem('delimiter', csvDelimiter);
csvDelimiter.delimiterChanged.connect(
(sender: CSVDelimiter, delimiter: string) => {
content.delimiter = delimiter;
content!.delimiter = delimiter;
}
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/docmanager-extension/src/index.ts
Expand Up @@ -695,8 +695,9 @@ function addLabCommands(
label: () => `Rename ${fileType(contextMenuWidget(), docManager)}…`,
isEnabled,
execute: () => {
// Implies contextMenuWidget() !== null
if (isEnabled()) {
let context = docManager.contextForWidget(contextMenuWidget());
let context = docManager.contextForWidget(contextMenuWidget()!);
return renameDialog(docManager, context!.path);
}
}
Expand Down
40 changes: 20 additions & 20 deletions packages/documentsearch/src/providers/notebooksearchprovider.ts
Expand Up @@ -52,7 +52,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
this._query = query;
// Listen for cell model change to redo the search in case of
// new/pasted/deleted cells
const cellList = this._searchTarget.model.cells;
const cellList = this._searchTarget.model!.cells;
cellList.changed.connect(this._restartQuery.bind(this), this);

// hide the current notebook widget to prevent expensive layout re-calculation operations
Expand Down Expand Up @@ -124,7 +124,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
this._searchTarget.show();

this._currentMatch = await this._stepNext(
this._searchTarget.content.activeCell
this._searchTarget.content.activeCell!
);
this._refreshCurrentCellEditor();

Expand Down Expand Up @@ -155,8 +155,8 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
* Refresh the editor in the cell for the current match.
*/
private _refreshCurrentCellEditor() {
const notebook = this._searchTarget.content;
notebook.activeCell.editor.refresh();
const notebook = this._searchTarget!.content;
notebook.activeCell!.editor.refresh();
}

/**
Expand All @@ -167,14 +167,14 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
* begin a new search.
*/
async endQuery(): Promise<void> {
this._searchTarget.hide();
this._searchTarget!.hide();

const queriesEnded: Promise<void>[] = [];
this._cmSearchProviders.forEach(({ provider }) => {
queriesEnded.push(provider.endQuery());
provider.changed.disconnect(this._onCmSearchProviderChanged, this);
});
Signal.disconnectBetween(this._searchTarget.model.cells, this);
Signal.disconnectBetween(this._searchTarget!.model!.cells, this);

this._cmSearchProviders = [];
this._unRenderedMarkdownCells.forEach((cell: MarkdownCell) => {
Expand All @@ -185,7 +185,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
});
this._unRenderedMarkdownCells = [];
await Promise.all(queriesEnded);
this._searchTarget.show();
this._searchTarget!.show();

this._refreshCurrentCellEditor();
// re-render all non-markdown cells with matches (which were rendered, thus do not need refreshing)
Expand All @@ -203,10 +203,10 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
* @returns A promise that resolves when all state has been cleaned up.
*/
async endSearch(): Promise<void> {
this._searchTarget.hide();
Signal.disconnectBetween(this._searchTarget.model.cells, this);
this._searchTarget!.hide();
Signal.disconnectBetween(this._searchTarget!.model!.cells, this);

const index = this._searchTarget.content.activeCellIndex;
const index = this._searchTarget!.content.activeCellIndex;
const searchEnded: Promise<void>[] = [];
this._cmSearchProviders.forEach(({ provider }) => {
searchEnded.push(provider.endSearch());
Expand All @@ -219,11 +219,11 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
});
this._unRenderedMarkdownCells = [];

this._searchTarget.content.activeCellIndex = index;
this._searchTarget.content.mode = 'edit';
this._searchTarget!.content.activeCellIndex = index;
this._searchTarget!.content.mode = 'edit';
this._currentMatch = null;
await Promise.all(searchEnded);
this._searchTarget.show();
this._searchTarget!.show();
this._refreshCurrentCellEditor();
this._searchTarget = null;

Expand All @@ -243,7 +243,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
*/
async highlightNext(): Promise<ISearchMatch | undefined> {
this._currentMatch = await this._stepNext(
this._searchTarget.content.activeCell
this._searchTarget!.content.activeCell!
);
return this._currentMatch;
}
Expand All @@ -255,7 +255,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
*/
async highlightPrevious(): Promise<ISearchMatch | undefined> {
this._currentMatch = await this._stepNext(
this._searchTarget.content.activeCell,
this._searchTarget!.content.activeCell!,
true
);
return this._currentMatch;
Expand All @@ -267,11 +267,11 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
* @returns A promise that resolves with a boolean indicating whether a replace occurred.
*/
async replaceCurrentMatch(newText: string): Promise<boolean> {
const notebook = this._searchTarget.content;
const editor = notebook.activeCell.editor as CodeMirrorEditor;
const notebook = this._searchTarget!.content;
const editor = notebook.activeCell!.editor as CodeMirrorEditor;
let replaceOccurred = false;
if (this._currentMatchIsSelected(editor)) {
const cellIndex = notebook.widgets.indexOf(notebook.activeCell);
const cellIndex = notebook.widgets.indexOf(notebook.activeCell!);
const { provider } = this._cmSearchProviders[cellIndex];
replaceOccurred = await provider.replaceCurrentMatch(newText);
if (replaceOccurred) {
Expand Down Expand Up @@ -348,7 +348,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {
reverse = false,
steps = 0
): Promise<ISearchMatch | undefined> {
const notebook = this._searchTarget.content;
const notebook = this._searchTarget!.content;
const cellIndex = notebook.widgets.indexOf(activeCell);
const numCells = notebook.widgets.length;
const { provider } = this._cmSearchProviders[cellIndex];
Expand Down Expand Up @@ -389,7 +389,7 @@ export class NotebookSearchProvider implements ISearchProvider<NotebookPanel> {

private async _restartQuery() {
await this.endQuery();
await this.startQuery(this._query, this._searchTarget);
await this.startQuery(this._query, this._searchTarget!);
this._changed.emit(undefined);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/documentsearch/src/searchoverlay.tsx
Expand Up @@ -459,7 +459,7 @@ export function createSearchOverlay(
onEndSearch={onEndSearch}
onReplaceCurrent={onReplaceCurrent}
onReplaceAll={onReplaceAll}
overlayState={args}
overlayState={args!}
isReadOnly={isReadOnly}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/filebrowser-extension/src/index.ts
Expand Up @@ -509,7 +509,7 @@ function addCommands(
// The normal contents service errors on paths ending in slash
path = path.slice(0, path.length - 1);
}
const browserForPath = Private.getBrowserForPath(path, factory);
const browserForPath = Private.getBrowserForPath(path, factory)!;
const { services } = browserForPath.model.manager;
const item = await services.contents.get(path, {
content: false
Expand Down Expand Up @@ -611,7 +611,7 @@ function addCommands(
}

return widget.model.manager.services.contents
.getDownloadUrl(widget.selectedItems().next().path)
.getDownloadUrl(widget.selectedItems().next()!.path)
.then(url => {
Clipboard.copyToSystem(url);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/filebrowser/src/listing.ts
Expand Up @@ -1242,7 +1242,7 @@ export class DirListing extends Widget {
void 0,
options
);
this._manager.openOrReveal(item.path);
this._manager.openOrReveal(item!.path);
});
});
firstWidgetPlaced.resolve(void 0);
Expand Down Expand Up @@ -1498,7 +1498,7 @@ export class DirListing extends Widget {

void this.selectItemByName(name)
.then(() => {
if (!this.isDisposed && newValue.type === 'directory') {
if (!this.isDisposed && newValue!.type === 'directory') {
return this._doRename();
}
})
Expand Down
6 changes: 3 additions & 3 deletions packages/logconsole-extension/src/status.tsx
Expand Up @@ -264,7 +264,7 @@ export namespace LogConsoleStatus {
if (source === null || version === null) {
return;
}
const versions = this._sourceVersion.get(source);
const versions = this._sourceVersion.get(source)!;
let change = false;
if (versions.lastDisplayed < version) {
versions.lastDisplayed = version;
Expand All @@ -290,8 +290,8 @@ export namespace LogConsoleStatus {
return;
}
const versions = this._sourceVersion.get(source);
if (versions.lastNotified < version) {
versions.lastNotified = version;
if (versions!.lastNotified < version) {
versions!.lastNotified = version;
if (source === this._source) {
this.stateChanged.emit();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mainmenu-extension/src/index.ts
Expand Up @@ -861,7 +861,7 @@ namespace Private {
// Typescript 2.8, we can possibly use conditional types to get Typescript
// to recognize this is a function.
let f = (extender[executor] as any) as (w: Widget) => Promise<any>;
return f(widget);
return f(widget!);
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/notebook-extension/src/index.ts
Expand Up @@ -1679,8 +1679,8 @@ function addCommands(

// Remove the output view if the parent notebook is closed.
current.content.disposed.connect(() => {
current.context.pathChanged.disconnect(updateCloned);
current.context.model.cells.changed.disconnect(updateCloned);
current!.context.pathChanged.disconnect(updateCloned);
current!.context.model?.cells.changed.disconnect(updateCloned);
widget.dispose();
});
},
Expand Down