Skip to content

Commit

Permalink
Use TypeScript strict mode (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Mar 8, 2024
1 parent 1639053 commit 446c8ac
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 40 deletions.
2 changes: 1 addition & 1 deletion js/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const outDir = "../shiny/www/shared/py-shiny";

async function bundle_helper(
options: BuildOptions
): Promise<ReturnType<typeof build>> {
): Promise<ReturnType<typeof build> | undefined> {
try {
const result = await build({
format: "esm",
Expand Down
22 changes: 11 additions & 11 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/node": "^20.2.5",
"@types/react": "^18.0.33",
"@types/react-dom": "^18.0.11",
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.7.4",
"@types/rstudio-shiny": "git+https://git@github.com/rstudio/shiny.git#v1.8.0",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"esbuild": "^0.18.11",
Expand Down
7 changes: 4 additions & 3 deletions js/page-output/page-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ class PageOutputBinding extends Shiny.OutputBinding {
}

onValueError(el: HTMLElement, err: ErrorsMessageValue): void {
Shiny.unbindAll(el);
if (Shiny.unbindAll) Shiny.unbindAll(el);
this.renderError(el, err);
}

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

await Shiny.renderContent(el, data);
await Shiny.renderContentAsync(el, data);
}
}

Expand Down
16 changes: 9 additions & 7 deletions js/text-area/textarea-autoresize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export interface DOMEvent<T extends EventTarget> extends Event {
function onDelegatedEvent(
eventName: string,
selector: string,
callback: (target: EventTarget) => void
callback: (target: HTMLTextAreaElement) => void
) {
document.addEventListener(eventName, (e: DOMEvent<HTMLTextAreaElement>) => {
if (e.target.matches(selector)) {
callback(e.target);
document.addEventListener(eventName, (e) => {
const e2 = e as DOMEvent<HTMLTextAreaElement>;
if (e2.target.matches(selector)) {
callback(e2.target);
}
});
}
Expand Down Expand Up @@ -41,8 +42,9 @@ function update_on_load() {
}

// document.readyState in ["interactive", "complete"];\
document
.querySelectorAll("textarea.textarea-autoresize")
.forEach(update_height);
const textAreas = document.querySelectorAll(
"textarea.textarea-autoresize"
) as NodeListOf<HTMLTextAreaElement>;
textAreas.forEach(update_height);
}
update_on_load();
20 changes: 14 additions & 6 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"compilerOptions": {
"module": "ES2020",
"lib": ["ES2021", "DOM"],
"module": "ES2022",
"lib": ["ES2022", "dom", "dom.iterable"],
"jsx": "react",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "ES2020",
"isolatedModules": true,
"moduleResolution": "node",
"esModuleInterop": true
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ES2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"strict": true,
"noUncheckedIndexedAccess": true
},
"include": ["**/*.tsx", "**/*.ts"]
"include": ["**/*.tsx", "**/*.ts"],
"exclude": ["dataframe/*"],
}
2 changes: 1 addition & 1 deletion shiny/www/shared/py-shiny/dataframe/dataframe.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shiny/www/shared/py-shiny/dataframe/dataframe.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions shiny/www/shared/py-shiny/page-output/page-output.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// page-output/page-output.ts
var PageOutputBinding = class extends Shiny.OutputBinding {
constructor() {
super(...arguments);
this.originalBodyTagAttrs = null;
}
originalBodyTagAttrs = null;
find(scope) {
return $(scope).find(".shiny-page-output");
}
onValueError(el, err) {
Shiny.unbindAll(el);
if (Shiny.unbindAll)
Shiny.unbindAll(el);
this.renderError(el, err);
}
async renderValue(el, data) {
if (data === null)
return;
if (el !== document.body) {
throw new Error(
'Output with class "shiny-page-output" must be a <body> tag.'
Expand Down Expand Up @@ -45,7 +45,7 @@ var PageOutputBinding = class extends Shiny.OutputBinding {
} else {
data.html = content;
}
await Shiny.renderContent(el, data);
await Shiny.renderContentAsync(el, data);
}
};
Shiny.outputBindings.register(
Expand Down
10 changes: 7 additions & 3 deletions shiny/www/shared/py-shiny/text-area/textarea-autoresize.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// text-area/textarea-autoresize.ts
function onDelegatedEvent(eventName, selector, callback) {
document.addEventListener(eventName, (e) => {
if (e.target.matches(selector)) {
callback(e.target);
const e2 = e;
if (e2.target.matches(selector)) {
callback(e2.target);
}
});
}
Expand All @@ -22,6 +23,9 @@ function update_on_load() {
setTimeout(update_on_load, 10);
return;
}
document.querySelectorAll("textarea.textarea-autoresize").forEach(update_height);
const textAreas = document.querySelectorAll(
"textarea.textarea-autoresize"
);
textAreas.forEach(update_height);
}
update_on_load();

0 comments on commit 446c8ac

Please sign in to comment.