Skip to content

Commit 6ddc642

Browse files
authored
Merge pull request #3571 from vidartf/narrow-deserialize
Narrow deserialize and improve strictness
2 parents 3a60698 + c5256da commit 6ddc642

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

packages/base/src/errorwidget.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BROKEN_FILE_SVG_ICON } from './utils';
99

1010
// create a Widget Model that captures an error object
1111
export function createErrorWidgetModel(
12-
error: Error,
12+
error: unknown,
1313
msg?: string
1414
): typeof WidgetModel {
1515
class ErrorWidget extends DOMWidgetModel {
@@ -78,12 +78,15 @@ export class ErrorWidgetView extends DOMWidgetView {
7878
}
7979

8080
export function createErrorWidgetView(
81-
error?: Error,
81+
error?: unknown,
8282
msg?: string
8383
): typeof WidgetView {
8484
return class InnerErrorWidgetView extends ErrorWidgetView {
8585
generateErrorMessage(): { msg?: string; stack: string } {
86-
return { msg, stack: String(error?.stack) };
86+
return {
87+
msg,
88+
stack: String(error instanceof Error ? error.stack : error),
89+
};
8790
}
8891
};
8992
}

packages/base/src/widget.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ export class WidgetModel extends Backbone.Model {
295295
try {
296296
this.set(state);
297297
} catch (e) {
298-
console.error(`Error setting state: ${e.message}`);
298+
console.error(
299+
`Error setting state: ${e instanceof Error ? e.message : e}`
300+
);
299301
} finally {
300302
this._state_lock = null;
301303
}
@@ -653,9 +655,9 @@ export class WidgetModel extends Backbone.Model {
653655
static _deserialize_state(
654656
state: Dict<BufferJSON>,
655657
manager: IWidgetManager
656-
): Promise<utils.Dict<BufferJSON>> {
658+
): Promise<utils.Dict<unknown>> {
657659
const serializers = this.serializers;
658-
let deserialized: Dict<PromiseLike<BufferJSON> | BufferJSON>;
660+
let deserialized: Dict<unknown>;
659661
if (serializers) {
660662
deserialized = {};
661663
for (const k in state) {

tsconfigbase.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"noUnusedLocals": true,
1616
"preserveWatchOutput": true,
1717
"resolveJsonModule": true,
18-
"strictNullChecks": true,
18+
"strict": true,
19+
"noImplicitThis": false,
20+
"strictPropertyInitialization": false,
21+
"strictFunctionTypes": false,
1922
"target": "es2017"
2023
}
2124
}

0 commit comments

Comments
 (0)