Skip to content

Commit 446c8ac

Browse files
authored
Use TypeScript strict mode (#1208)
1 parent 1639053 commit 446c8ac

File tree

10 files changed

+55
-40
lines changed

10 files changed

+55
-40
lines changed

js/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const outDir = "../shiny/www/shared/py-shiny";
66

77
async function bundle_helper(
88
options: BuildOptions
9-
): Promise<ReturnType<typeof build>> {
9+
): Promise<ReturnType<typeof build> | undefined> {
1010
try {
1111
const result = await build({
1212
format: "esm",

js/package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/node": "^20.2.5",
1818
"@types/react": "^18.0.33",
1919
"@types/react-dom": "^18.0.11",
20-
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.7.4",
20+
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.8.0",
2121
"@typescript-eslint/eslint-plugin": "^5.59.7",
2222
"@typescript-eslint/parser": "^5.59.7",
2323
"esbuild": "^0.18.11",

js/page-output/page-output.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ class PageOutputBinding extends Shiny.OutputBinding {
88
}
99

1010
onValueError(el: HTMLElement, err: ErrorsMessageValue): void {
11-
Shiny.unbindAll(el);
11+
if (Shiny.unbindAll) Shiny.unbindAll(el);
1212
this.renderError(el, err);
1313
}
1414

1515
async renderValue(
1616
el: HTMLElement,
17-
data: Parameters<typeof Shiny.renderContent>[1]
17+
data: Parameters<typeof Shiny.renderContentAsync>[1]
1818
): Promise<void> {
19+
if (data === null) return;
1920
if (el !== document.body) {
2021
throw new Error(
2122
'Output with class "shiny-page-output" must be a <body> tag.'
@@ -66,7 +67,7 @@ class PageOutputBinding extends Shiny.OutputBinding {
6667
data.html = content;
6768
}
6869

69-
await Shiny.renderContent(el, data);
70+
await Shiny.renderContentAsync(el, data);
7071
}
7172
}
7273

js/text-area/textarea-autoresize.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export interface DOMEvent<T extends EventTarget> extends Event {
88
function onDelegatedEvent(
99
eventName: string,
1010
selector: string,
11-
callback: (target: EventTarget) => void
11+
callback: (target: HTMLTextAreaElement) => void
1212
) {
13-
document.addEventListener(eventName, (e: DOMEvent<HTMLTextAreaElement>) => {
14-
if (e.target.matches(selector)) {
15-
callback(e.target);
13+
document.addEventListener(eventName, (e) => {
14+
const e2 = e as DOMEvent<HTMLTextAreaElement>;
15+
if (e2.target.matches(selector)) {
16+
callback(e2.target);
1617
}
1718
});
1819
}
@@ -41,8 +42,9 @@ function update_on_load() {
4142
}
4243

4344
// document.readyState in ["interactive", "complete"];\
44-
document
45-
.querySelectorAll("textarea.textarea-autoresize")
46-
.forEach(update_height);
45+
const textAreas = document.querySelectorAll(
46+
"textarea.textarea-autoresize"
47+
) as NodeListOf<HTMLTextAreaElement>;
48+
textAreas.forEach(update_height);
4749
}
4850
update_on_load();

js/tsconfig.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
22
"compilerOptions": {
3-
"module": "ES2020",
4-
"lib": ["ES2021", "DOM"],
3+
"module": "ES2022",
4+
"lib": ["ES2022", "dom", "dom.iterable"],
55
"jsx": "react",
66
"noImplicitAny": true,
77
"removeComments": true,
88
"preserveConstEnums": true,
99
"sourceMap": true,
10-
"target": "ES2020",
11-
"isolatedModules": true,
1210
"moduleResolution": "node",
13-
"esModuleInterop": true
11+
"noEmit": true,
12+
"esModuleInterop": true,
13+
"skipLibCheck": true,
14+
"target": "ES2022",
15+
"allowJs": true,
16+
"resolveJsonModule": true,
17+
"moduleDetection": "force",
18+
"isolatedModules": true,
19+
"strict": true,
20+
"noUncheckedIndexedAccess": true
1421
},
15-
"include": ["**/*.tsx", "**/*.ts"]
22+
"include": ["**/*.tsx", "**/*.ts"],
23+
"exclude": ["dataframe/*"],
1624
}

shiny/www/shared/py-shiny/dataframe/dataframe.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/shared/py-shiny/dataframe/dataframe.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/shared/py-shiny/page-output/page-output.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// page-output/page-output.ts
22
var PageOutputBinding = class extends Shiny.OutputBinding {
3-
constructor() {
4-
super(...arguments);
5-
this.originalBodyTagAttrs = null;
6-
}
3+
originalBodyTagAttrs = null;
74
find(scope) {
85
return $(scope).find(".shiny-page-output");
96
}
107
onValueError(el, err) {
11-
Shiny.unbindAll(el);
8+
if (Shiny.unbindAll)
9+
Shiny.unbindAll(el);
1210
this.renderError(el, err);
1311
}
1412
async renderValue(el, data) {
13+
if (data === null)
14+
return;
1515
if (el !== document.body) {
1616
throw new Error(
1717
'Output with class "shiny-page-output" must be a <body> tag.'
@@ -45,7 +45,7 @@ var PageOutputBinding = class extends Shiny.OutputBinding {
4545
} else {
4646
data.html = content;
4747
}
48-
await Shiny.renderContent(el, data);
48+
await Shiny.renderContentAsync(el, data);
4949
}
5050
};
5151
Shiny.outputBindings.register(

shiny/www/shared/py-shiny/text-area/textarea-autoresize.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// text-area/textarea-autoresize.ts
22
function onDelegatedEvent(eventName, selector, callback) {
33
document.addEventListener(eventName, (e) => {
4-
if (e.target.matches(selector)) {
5-
callback(e.target);
4+
const e2 = e;
5+
if (e2.target.matches(selector)) {
6+
callback(e2.target);
67
}
78
});
89
}
@@ -22,6 +23,9 @@ function update_on_load() {
2223
setTimeout(update_on_load, 10);
2324
return;
2425
}
25-
document.querySelectorAll("textarea.textarea-autoresize").forEach(update_height);
26+
const textAreas = document.querySelectorAll(
27+
"textarea.textarea-autoresize"
28+
);
29+
textAreas.forEach(update_height);
2630
}
2731
update_on_load();

0 commit comments

Comments
 (0)