Просмотр исходного кода

ref(ts) Convert platform data to typescript (#18512)

Add integration-platform-docs to tsc loader and enable json loading

This is required for tsc to resolve the types on the JSON file which
necessitated relaxing the types on PlatformIntegration.
Mark Story 4 лет назад
Родитель
Сommit
b144a4346d

+ 2 - 1
src/sentry/static/sentry/app/data/platforms.jsx → src/sentry/static/sentry/app/data/platforms.tsx

@@ -1,4 +1,5 @@
 /* eslint import/no-unresolved:0 import/order:0 */
+import {PlatformIntegration} from 'app/types';
 import {platforms} from 'integration-docs-platforms';
 import {t} from 'app/locale';
 
@@ -15,7 +16,7 @@ const otherPlatform = {
   name: t('Other'),
 };
 
-export default [].concat(
+export default ([] as PlatformIntegration[]).concat(
   [],
   ...[...platforms, otherPlatform].map(platform =>
     platform.integrations.map(i => ({...i, language: platform.id}))

+ 8 - 0
src/sentry/static/sentry/app/types/index.tsx

@@ -1187,3 +1187,11 @@ export type Activity = {
   project: Project;
   user?: User;
 };
+
+export type PlatformIntegration = {
+  id: string;
+  type: string;
+  language: string;
+  link: string | null;
+  name: string;
+};

+ 8 - 1
tsconfig.json

@@ -20,6 +20,7 @@
     "noUnusedLocals": true,
     "noUnusedParameters": true,
     "pretty": false,
+    "resolveJsonModule": true,
     "sourceMap": true,
     "strict": true,
     "target": "es5",
@@ -35,7 +36,13 @@
       "app/*": ["src/sentry/static/sentry/app/*"],
       "sentry-test/*": ["tests/js/sentry-test/*"],
       "@emotion/styled": ["src/sentry/static/sentry/app/styled.tsx"],
-      "@original-emotion/*": ["node_modules/@emotion/*"]
+      "@original-emotion/*": ["node_modules/@emotion/*"],
+      // Use the stub file for typechecking. Webpack resolver will use the real files
+      // based on configuration.
+      "integration-docs-platforms": [
+          "tests/fixtures/integration-docs/_platforms.json",
+          "src/sentry/integration-docs/_platforms.json"
+      ]
     },
     "plugins": [{"name": "typescript-styled-plugin"}]
   },