From 83ff59e13c2b6d84c4dc74ee0e63cdb5a86ae11f Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 23 May 2024 17:22:14 -0700 Subject: [PATCH 1/4] Copy TSConfig from Auspice This ruleset was curated by and for the Nextstrain core team. --- static-site/tsconfig.json | 64 +++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/static-site/tsconfig.json b/static-site/tsconfig.json index 4e224ad41..c5b458c99 100644 --- a/static-site/tsconfig.json +++ b/static-site/tsconfig.json @@ -1,27 +1,53 @@ +/* +Much of Auspice was written in JavaScript. There is an effort to convert +existing JavaScript files to TypeScript in an iterative, file-by-file approach. + +TypeScript is used in this project for type-checking only, not for its compiled +output files - Babel is used for that. Config options should reflect this usage +pattern. + +Visit https://aka.ms/tsconfig.json for a detailed list of options. +*/ + { "compilerOptions": { - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "strict": false, - "forceConsistentCasingInFileNames": true, - "noEmit": true, - "incremental": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve" + /* Language and Environment */ + "jsx": "react", /* Specify what JSX code is generated. */ + + /* Modules */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "types": ["node"], /* Specify type package names to be included without being referenced in a source file. */ + + /* JavaScript Support */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. This allows TS files to import from JS files. */ + + /* Emit */ + "noEmit": true, /* Do not emit compiler output files like JavaScript source code, source-maps or declarations. */ + + /* Interop Constraints */ + "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Allow implicit any to make incremental TypeScript adoption easier. */ + "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + "allowUnusedLabels": false, /* Enable error reporting for unused labels. */ + "allowUnreachableCode": false, /* Enable error reporting for unreachable code. */ + + /* Completeness */ + "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ }, "include": [ "next-env.d.ts", - "**/*.ts", - "**/*.tsx" + "src/**/*", ], "exclude": [ "node_modules" From 568897dc078c7893aae721b184fa90a22a9019c4 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 23 May 2024 17:32:37 -0700 Subject: [PATCH 2/4] Make TSConfig work with with Next.js I let `npm run dev` rewrite the file which added some options and applied some whitespace reformatting. To minimize the amount of changes in this commit, I restored the original whitespace reformatting then re-added the Next.js options. --- static-site/tsconfig.json | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/static-site/tsconfig.json b/static-site/tsconfig.json index c5b458c99..da5a9bf41 100644 --- a/static-site/tsconfig.json +++ b/static-site/tsconfig.json @@ -1,18 +1,16 @@ /* -Much of Auspice was written in JavaScript. There is an effort to convert -existing JavaScript files to TypeScript in an iterative, file-by-file approach. +This TSConfig file aims to keep as much as possible in sync with the same file +in Auspice¹. -TypeScript is used in this project for type-checking only, not for its compiled -output files - Babel is used for that. Config options should reflect this usage -pattern. +It can't be 100% the same because Next.js requires some configuration options to +be set and will rewrite this file if they aren't set.² -Visit https://aka.ms/tsconfig.json for a detailed list of options. +¹ +² https://github.com/vercel/next.js/discussions/39942 */ { "compilerOptions": { - /* Language and Environment */ - "jsx": "react", /* Specify what JSX code is generated. */ /* Modules */ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ @@ -44,6 +42,18 @@ Visit https://aka.ms/tsconfig.json for a detailed list of options. /* Completeness */ "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + + /* Other options required by Next.js */ + "jsx": "preserve", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "incremental": true, + "esModuleInterop": true, + "module": "esnext", + "resolveJsonModule": true, }, "include": [ "next-env.d.ts", From 8d45cc352916cd837999bf40d3f910adcaba0dee Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 23 May 2024 18:57:05 -0700 Subject: [PATCH 3/4] Ignore static-site/tsconfig.tsbuildinfo This is generated upon running tsc. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ad1457036..b6e79ca14 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ terraform.tfstate* # nextjs static-site/next-env.d.ts static-site/.next + +# TypeScript +static-site/tsconfig.tsbuildinfo From a7bd07cd8caf93844fc48d2e3649f3080855437f Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Tue, 28 May 2024 10:27:16 -0700 Subject: [PATCH 4/4] Apply TSConfig to files under static-site/pages/ static-site/src/ was mirrored from Auspice, but the include filepaths should be project-specific. pages/ contains source files for this project and should be added. --- static-site/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/static-site/tsconfig.json b/static-site/tsconfig.json index da5a9bf41..62fe985f5 100644 --- a/static-site/tsconfig.json +++ b/static-site/tsconfig.json @@ -57,6 +57,7 @@ be set and will rewrite this file if they aren't set.² }, "include": [ "next-env.d.ts", + "pages/**/*", "src/**/*", ], "exclude": [