From 7c1305b3a4ce0ee39aa923a1f1ac604794265b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=9F=E3=81=84=E3=81=A1=20=E3=81=B2?= Date: Mon, 8 May 2023 18:28:36 +0900 Subject: [PATCH] Add TypeScript support for `mastodon` alias and image imports (#24895) --- .../mastodon/components/hashtag.jsx | 2 -- app/javascript/types/image.d.ts | 34 +++++++++++++++++++ tsconfig.json | 13 +++++-- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 app/javascript/types/image.d.ts diff --git a/app/javascript/mastodon/components/hashtag.jsx b/app/javascript/mastodon/components/hashtag.jsx index 254fae2fe09..d03b1a45a76 100644 --- a/app/javascript/mastodon/components/hashtag.jsx +++ b/app/javascript/mastodon/components/hashtag.jsx @@ -5,9 +5,7 @@ import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { Link } from 'react-router-dom'; -// @ts-expect-error import ShortNumber from 'mastodon/components/short_number'; -// @ts-expect-error import Skeleton from 'mastodon/components/skeleton'; import classNames from 'classnames'; diff --git a/app/javascript/types/image.d.ts b/app/javascript/types/image.d.ts new file mode 100644 index 00000000000..8bd6ab02862 --- /dev/null +++ b/app/javascript/types/image.d.ts @@ -0,0 +1,34 @@ +declare module '*.avif' { + const path: string; + export default path; +} + +declare module '*.gif' { + const path: string; + export default path; +} + +declare module '*.jpg' { + const path: string; + export default path; +} + +declare module '*.jpg' { + const path: string; + export default path; +} + +declare module '*.png' { + const path: string; + export default path; +} + +declare module '*.svg' { + const path: string; + export default path; +} + +declare module '*.webp' { + const path: string; + export default path; +} diff --git a/tsconfig.json b/tsconfig.json index 505b19d89b6..09cea2a75f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,16 @@ "noEmit": true, "strict": true, "esModuleInterop": true, - "skipLibCheck": true + "skipLibCheck": true, + "baseUrl": "./", + "paths": { + "mastodon": ["app/javascript/mastodon"], + "mastodon/*": ["app/javascript/mastodon/*"] + } }, - "include": ["app/javascript/mastodon", "app/javascript/packs"] + "include": [ + "app/javascript/mastodon", + "app/javascript/packs", + "app/javascript/types" + ] }