WebUI: Use different TS config for Polymer Desktop vs CrOS UIs.

This will allow turning on the new `noUncheckedSideEffectImports` TS
flag [1] on Polymer Desktop UIs first, without being blocked on fixing
all violations across CrOS WebUI.

[1] https://www.typescriptlang.org/tsconfig/#noUncheckedSideEffectImports

Bug: 374334459
Change-Id: I9fd4ee90664e4064b754f914c424f2cf0c5297ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5959427
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1373623}
diff --git a/ash/webui/common/resources/BUILD.gn b/ash/webui/common/resources/BUILD.gn
index 9aa934a8..f094f22 100644
--- a/ash/webui/common/resources/BUILD.gn
+++ b/ash/webui/common/resources/BUILD.gn
@@ -265,7 +265,7 @@
 }
 
 webui_ts_library("build_ts") {
-  tsconfig_base = "//tools/typescript/tsconfig_base_polymer.json"
+  tsconfig_base = "//tools/typescript/tsconfig_base_polymer_cros.json"
   root_dir = preprocessed_dir
   out_dir = preprocessed_dir
   in_files = non_web_component_files_ts + web_component_files_ts +
diff --git a/ash/webui/common/resources/cellular_setup/tsconfig_base.json b/ash/webui/common/resources/cellular_setup/tsconfig_base.json
index 9ceb5a8..a128513 100644
--- a/ash/webui/common/resources/cellular_setup/tsconfig_base.json
+++ b/ash/webui/common/resources/cellular_setup/tsconfig_base.json
@@ -1,5 +1,5 @@
 {
-  "extends": "../../../../../tools/typescript/tsconfig_base_polymer.json",
+  "extends": "../../../../../tools/typescript/tsconfig_base_polymer_cros.json",
   "compilerOptions": {
     "typeRoots": ["../../../../../third_party/node/node_modules/@types"],
     "types": [
diff --git a/ash/webui/diagnostics_ui/resources/tsconfig_base.json b/ash/webui/diagnostics_ui/resources/tsconfig_base.json
index 613a4ca..4f90e951 100644
--- a/ash/webui/diagnostics_ui/resources/tsconfig_base.json
+++ b/ash/webui/diagnostics_ui/resources/tsconfig_base.json
@@ -1,5 +1,5 @@
 {
-    "extends": "../../../../tools/typescript/tsconfig_base_polymer.json",
+    "extends": "../../../../tools/typescript/tsconfig_base_polymer_cros.json",
     "compilerOptions": {
       "allowUmdGlobalAccess": true,
       "typeRoots": [ "../../../../third_party/node/node_modules/@types" ],
diff --git a/chrome/browser/resources/ash/settings/tsconfig_base.json b/chrome/browser/resources/ash/settings/tsconfig_base.json
index 9ceb5a8..a128513 100644
--- a/chrome/browser/resources/ash/settings/tsconfig_base.json
+++ b/chrome/browser/resources/ash/settings/tsconfig_base.json
@@ -1,5 +1,5 @@
 {
-  "extends": "../../../../../tools/typescript/tsconfig_base_polymer.json",
+  "extends": "../../../../../tools/typescript/tsconfig_base_polymer_cros.json",
   "compilerOptions": {
     "typeRoots": ["../../../../../third_party/node/node_modules/@types"],
     "types": [
diff --git a/tools/typescript/path_utils.py b/tools/typescript/path_utils.py
index ab87f57..2d6545e 100644
--- a/tools/typescript/path_utils.py
+++ b/tools/typescript/path_utils.py
@@ -20,6 +20,7 @@
       'chrome/browser/resources/ash',
       'chrome/browser/resources/chromeos',
       'chrome/browser/resources/dlp_internals',
+      'chromeos/ash/components/kiosk/vision/webui',
       'ui/file_manager',
 
       # Test folders
diff --git a/tools/typescript/tsconfig_base_polymer_cros.json b/tools/typescript/tsconfig_base_polymer_cros.json
new file mode 100644
index 0000000..507bc8cc
--- /dev/null
+++ b/tools/typescript/tsconfig_base_polymer_cros.json
@@ -0,0 +1,9 @@
+{
+  "extends": "./tsconfig_base.json",
+  "compilerOptions": {
+    "noUncheckedIndexedAccess": false,
+    "noUnusedLocals": false,
+    "strictPropertyInitialization": false,
+    "useDefineForClassFields": false
+  }
+}
diff --git a/ui/webui/resources/tools/build_webui.gni b/ui/webui/resources/tools/build_webui.gni
index f64b098..415d789 100644
--- a/ui/webui/resources/tools/build_webui.gni
+++ b/ui/webui/resources/tools/build_webui.gni
@@ -23,6 +23,25 @@
   import("//chrome/common/features.gni")
 }
 
+if (is_chromeos_ash) {
+  # Folders hosting Ash-only WebUIs. Should be kept in sync with
+  # //tools/typescript/path_utils.py. This is used later in this file to choose
+  # a CrOS-specific default TS config file for some targets.
+  ash_folders = [
+    # Source code folders
+    "//ash/webui",
+    "//chrome/browser/resources/ash",
+    "//chrome/browser/resources/chromeos",
+    "//chrome/browser/resources/dlp_internals",
+    "//chromeos/ash/components/kiosk/vision/webui",
+    "//ui/file_manager",
+
+    # Test folders
+    "//chrome/test/data/webui/chromeos",
+    "//chrome/test/data/webui/cr_components/chromeos",
+  ]
+}
+
 # See documentation at https://chromium.googlesource.com/chromium/src/+/HEAD/docs/webui_build_configuration.md#build_webui
 template("build_webui") {
   not_needed([ "target_name" ])
@@ -340,6 +359,24 @@
                          [ "//third_party/polymer/v3_0:library" ]) != []
       if (has_polymer) {
         tsconfig_base = "//tools/typescript/tsconfig_base_polymer.json"
+
+        # Detect whether the target corresponds to an Ash-only WebUI and use
+        # tsconfig_base_polymer_cros.json instead in such cases.
+        if (is_chromeos_ash) {
+          is_ash_webui = false
+          target_dir = get_label_info(":build_ts", "dir")
+
+          foreach(prefix, ash_folders) {
+            if (!is_ash_webui) {
+              is_ash_webui =
+                  string_replace(target_dir, prefix, "") != target_dir
+            }
+          }
+
+          if (is_ash_webui) {
+            tsconfig_base = "//tools/typescript/tsconfig_base_polymer_cros.json"
+          }
+        }
       } else {
         has_lit = filter_include(invoker.ts_deps,
                                  [ "//third_party/lit/v3_0:build_ts" ]) != []