Skip to content

Commit fb606be

Browse files
committed
Add typings for strict null checks
1 parent 148c2c4 commit fb606be

7 files changed

Lines changed: 31 additions & 25 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"./vs/base/browser/ui/list/splice.ts",
2626
"./vs/base/browser/ui/octiconLabel/octiconLabel.mock.ts",
2727
"./vs/base/browser/ui/octiconLabel/octiconLabel.ts",
28+
"./vs/base/browser/ui/progressbar/progressbar.ts",
2829
"./vs/base/browser/ui/scrollbar/abstractScrollbar.ts",
2930
"./vs/base/browser/ui/scrollbar/horizontalScrollbar.ts",
3031
"./vs/base/browser/ui/scrollbar/scrollableElement.ts",
@@ -35,7 +36,6 @@
3536
"./vs/base/browser/ui/scrollbar/verticalScrollbar.ts",
3637
"./vs/base/browser/ui/tree/tree.ts",
3738
"./vs/base/browser/ui/widget.ts",
38-
"./vs/base/common/actions.ts",
3939
"./vs/base/common/amd.ts",
4040
"./vs/base/common/arrays.ts",
4141
"./vs/base/common/assert.ts",
@@ -76,6 +76,7 @@
7676
"./vs/base/common/normalization.ts",
7777
"./vs/base/common/numbers.ts",
7878
"./vs/base/common/objects.ts",
79+
"./vs/base/common/octicon.ts",
7980
"./vs/base/common/paging.ts",
8081
"./vs/base/common/parsers.ts",
8182
"./vs/base/common/paths.ts",
@@ -100,6 +101,7 @@
100101
"./vs/base/node/id.ts",
101102
"./vs/base/node/paths.ts",
102103
"./vs/base/node/ports.ts",
104+
"./vs/base/node/request.ts",
103105
"./vs/base/parts/contextmenu/common/contextmenu.ts",
104106
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
105107
"./vs/base/parts/quickopen/common/quickOpen.ts",
@@ -316,6 +318,7 @@
316318
"./vs/editor/contrib/message/messageController.ts",
317319
"./vs/editor/contrib/parameterHints/provideSignatureHelp.ts",
318320
"./vs/editor/contrib/quickOpen/quickOpen.ts",
321+
"./vs/editor/contrib/suggest/suggest.ts",
319322
"./vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode.ts",
320323
"./vs/editor/contrib/wordHighlighter/wordHighlighter.ts",
321324
"./vs/editor/contrib/wordOperations/wordOperations.ts",
@@ -403,6 +406,7 @@
403406
"./vs/platform/quickOpen/common/quickOpen.ts",
404407
"./vs/platform/quickinput/common/quickInput.ts",
405408
"./vs/platform/registry/common/platform.ts",
409+
"./vs/platform/request/node/request.ts",
406410
"./vs/platform/search/common/search.ts",
407411
"./vs/platform/state/common/state.ts",
408412
"./vs/platform/statusbar/common/statusbar.ts",
@@ -424,6 +428,7 @@
424428
"./vs/platform/workspaces/common/workspaces.ts",
425429
"./vs/platform/workspaces/node/workspaces.ts",
426430
"./vs/workbench/api/shared/tasks.ts",
431+
"./vs/workbench/browser/part.ts",
427432
"./vs/workbench/browser/parts/quickinput/quickInputUtils.ts",
428433
"./vs/workbench/browser/parts/statusbar/statusbar.ts",
429434
"./vs/workbench/common/activity.ts",
@@ -461,6 +466,7 @@
461466
"./vs/workbench/parts/scm/common/scm.ts",
462467
"./vs/workbench/parts/scm/electron-browser/scmUtil.ts",
463468
"./vs/workbench/parts/search/common/constants.ts",
469+
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
464470
"./vs/workbench/parts/tasks/common/taskTemplates.ts",
465471
"./vs/workbench/parts/terminal/browser/terminalWidgetManager.ts",
466472
"./vs/workbench/parts/terminal/common/terminal.ts",

src/vs/base/browser/ui/progressbar/progressbar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class ProgressBar extends Disposable {
3737
private workedVal: number;
3838
private element: HTMLElement;
3939
private bit: HTMLElement;
40-
private totalWork: number;
41-
private progressBarBackground: Color;
40+
private totalWork: number | undefined;
41+
private progressBarBackground: Color | undefined;
4242
private showDelayedScheduler: RunOnceScheduler;
4343

4444
constructor(container: HTMLElement, options?: IProgressBarOptions) {
@@ -146,7 +146,7 @@ export class ProgressBar extends Disposable {
146146
* Finds out if this progress bar is configured with total work
147147
*/
148148
hasTotal(): boolean {
149-
return !isNaN(this.totalWork);
149+
return !isNaN(this.totalWork as number);
150150
}
151151

152152
/**
@@ -172,10 +172,10 @@ export class ProgressBar extends Disposable {
172172
}
173173

174174
private doSetWorked(value: number): ProgressBar {
175-
assert.ok(!isNaN(this.totalWork), 'Total work not set');
175+
assert.ok(!isNaN(this.totalWork as number), 'Total work not set');
176176

177177
this.workedVal = value;
178-
this.workedVal = Math.min(this.totalWork, this.workedVal);
178+
this.workedVal = Math.min(this.totalWork as number, this.workedVal);
179179

180180
if (hasClass(this.element, css_infinite)) {
181181
removeClass(this.element, css_infinite);
@@ -193,7 +193,7 @@ export class ProgressBar extends Disposable {
193193
addClass(this.element, css_discrete);
194194
}
195195

196-
this.bit.style.width = 100 * (this.workedVal / this.totalWork) + '%';
196+
this.bit.style.width = 100 * (this.workedVal / (this.totalWork as number)) + '%';
197197

198198
return this;
199199
}

src/vs/base/common/octicon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function doParseOcticons(text: string, firstOcticonIndex: number): IParsedOctico
9797
return { text: textWithoutOcticons, octiconOffsets };
9898
}
9999

100-
export function matchesFuzzyOcticonAware(query: string, target: IParsedOcticons, enableSeparateSubstringMatching = false): IMatch[] {
100+
export function matchesFuzzyOcticonAware(query: string, target: IParsedOcticons, enableSeparateSubstringMatching = false): IMatch[] | null {
101101
const { text, octiconOffsets } = target;
102102

103103
// Return early if there are no octicon markers in the word to match against

src/vs/base/node/request.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface IRequestFunction {
4949
}
5050

5151
async function getNodeRequest(options: IRequestOptions): Promise<IRawRequestFunction> {
52-
const endpoint = parseUrl(options.url);
52+
const endpoint = parseUrl(options.url!);
5353
const module = endpoint.protocol === 'https:' ? await import('https') : await import('http');
5454
return module.request;
5555
}
@@ -64,7 +64,7 @@ export function request(options: IRequestOptions, token: CancellationToken): Pro
6464
return rawRequestPromise.then(rawRequest => {
6565

6666
return new Promise<IRequestContext>((c, e) => {
67-
const endpoint = parseUrl(options.url);
67+
const endpoint = parseUrl(options.url!);
6868

6969
const opts: https.RequestOptions = {
7070
hostname: endpoint.hostname,
@@ -82,8 +82,8 @@ export function request(options: IRequestOptions, token: CancellationToken): Pro
8282
}
8383

8484
req = rawRequest(opts, (res: http.ClientResponse) => {
85-
const followRedirects = isNumber(options.followRedirects) ? options.followRedirects : 3;
86-
if (res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
85+
const followRedirects: number = isNumber(options.followRedirects) ? options.followRedirects : 3;
86+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers['location']) {
8787
request(assign({}, options, {
8888
url: res.headers['location'],
8989
followRedirects: followRedirects - 1
@@ -125,7 +125,7 @@ export function request(options: IRequestOptions, token: CancellationToken): Pro
125125
}
126126

127127
function isSuccess(context: IRequestContext): boolean {
128-
return (context.res.statusCode >= 200 && context.res.statusCode < 300) || context.res.statusCode === 1223;
128+
return (context.res.statusCode && context.res.statusCode >= 200 && context.res.statusCode < 300) || context.res.statusCode === 1223;
129129
}
130130

131131
function hasNoContent(context: IRequestContext): boolean {
@@ -136,13 +136,13 @@ export function download(filePath: string, context: IRequestContext): Promise<vo
136136
return new Promise<void>((c, e) => {
137137
const out = createWriteStream(filePath);
138138

139-
out.once('finish', () => c(null));
139+
out.once('finish', () => c(void 0));
140140
context.stream.once('error', e);
141141
context.stream.pipe(out);
142142
});
143143
}
144144

145-
export function asText(context: IRequestContext): Promise<string> {
145+
export function asText(context: IRequestContext): Promise<string | null> {
146146
return new Promise((c, e) => {
147147
if (!isSuccess(context)) {
148148
return e('Server returned ' + context.res.statusCode);
@@ -159,7 +159,7 @@ export function asText(context: IRequestContext): Promise<string> {
159159
});
160160
}
161161

162-
export function asJson<T>(context: IRequestContext): Promise<T> {
162+
export function asJson<T>(context: IRequestContext): Promise<T | null> {
163163
return new Promise((c, e) => {
164164
if (!isSuccess(context)) {
165165
return e('Server returned ' + context.res.statusCode);

src/vs/editor/contrib/suggest/suggest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function provideSuggestionItems(
8181
// for each support in the group ask for suggestions
8282
return Promise.all(supports.map(support => {
8383

84-
if (!isFalsyOrEmpty(onlyFrom) && onlyFrom.indexOf(support) < 0) {
84+
if (!isFalsyOrEmpty(onlyFrom) && onlyFrom!.indexOf(support) < 0) {
8585
return undefined;
8686
}
8787

src/vs/workbench/browser/part.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export interface IPartOptions {
2020
*/
2121
export abstract class Part extends Component {
2222
private parent: HTMLElement;
23-
private titleArea: HTMLElement;
24-
private contentArea: HTMLElement;
23+
private titleArea: HTMLElement | null;
24+
private contentArea: HTMLElement | null;
2525
private partLayout: PartLayout;
2626

2727
constructor(
@@ -67,28 +67,28 @@ export abstract class Part extends Component {
6767
/**
6868
* Subclasses override to provide a title area implementation.
6969
*/
70-
protected createTitleArea(parent: HTMLElement): HTMLElement {
70+
protected createTitleArea(parent: HTMLElement): HTMLElement | null {
7171
return null;
7272
}
7373

7474
/**
7575
* Returns the title area container.
7676
*/
77-
protected getTitleArea(): HTMLElement {
77+
protected getTitleArea(): HTMLElement | null {
7878
return this.titleArea;
7979
}
8080

8181
/**
8282
* Subclasses override to provide a content area implementation.
8383
*/
84-
protected createContentArea(parent: HTMLElement): HTMLElement {
84+
protected createContentArea(parent: HTMLElement): HTMLElement | null {
8585
return null;
8686
}
8787

8888
/**
8989
* Returns the content area container.
9090
*/
91-
protected getContentArea(): HTMLElement {
91+
protected getContentArea(): HTMLElement | null {
9292
return this.contentArea;
9393
}
9494

@@ -104,7 +104,7 @@ export class PartLayout {
104104

105105
private static readonly TITLE_HEIGHT = 35;
106106

107-
constructor(container: HTMLElement, private options: IPartOptions, titleArea: HTMLElement, private contentArea: HTMLElement) { }
107+
constructor(container: HTMLElement, private options: IPartOptions, titleArea: HTMLElement | null, private contentArea: HTMLElement | null) { }
108108

109109
layout(dimension: Dimension): Dimension[] {
110110
const { width, height } = dimension;

src/vs/workbench/parts/surveys/electron-browser/nps.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class NPSContribution implements IWorkbenchContribution {
3939
return;
4040
}
4141

42-
const sessionCount = storageService.getInteger(SESSION_COUNT_KEY, StorageScope.GLOBAL, 0) + 1;
42+
const sessionCount = (storageService.getInteger(SESSION_COUNT_KEY, StorageScope.GLOBAL, 0) || 0) + 1;
4343
storageService.store(LAST_SESSION_DATE_KEY, date, StorageScope.GLOBAL);
4444
storageService.store(SESSION_COUNT_KEY, sessionCount, StorageScope.GLOBAL);
4545

0 commit comments

Comments
 (0)