Skip to content

Commit 171a770

Browse files
feat: enable the use of TypeScript in this repo (#604)
* feat: enable Typescript in this repo * refactor: rename studio-header files to .ts[x] * chore: fix minor type warnings * chore: add types for frontend-platform * chore: fix type issues * chore: update name of suppressed lint check
1 parent f47c1ed commit 171a770

24 files changed

+75
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
run: make validate-no-uncommitted-package-lock-changes
2525
- name: Lint
2626
run: npm run lint
27+
- name: Type check
28+
run: npm run types
2729
- name: Test
2830
run: npm run test
2931
- name: Build

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: make validate-no-uncommitted-package-lock-changes
2626
- name: Lint
2727
run: npm run lint
28+
- name: Type check
29+
run: npm run types
2830
- name: Test
2931
run: npm run test
3032
- name: i18n_extract

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .",
1414
"snapshot": "fedx-scripts jest --updateSnapshot",
1515
"start": "fedx-scripts webpack-dev-server --progress",
16-
"test": "fedx-scripts jest --coverage"
16+
"test": "fedx-scripts jest --coverage",
17+
"types": "tsc --noEmit"
1718
},
1819
"files": [
1920
"/dist"

src/desktop-header/DesktopHeader.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import messages from '../Header.messages';
2222
import { CaretIcon } from '../Icons';
2323

2424
class DesktopHeader extends React.Component {
25-
constructor(props) { // eslint-disable-line no-useless-constructor
25+
constructor(props) { // eslint-disable-line @typescript-eslint/no-useless-constructor
2626
super(props);
2727
}
2828

src/frontend-platform.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// frontend-platform currently doesn't provide types... do it ourselves for i18n module at least.
2+
// We can remove this in the future when we migrate to frontend-shell, or when frontend-platform gets types
3+
// (whichever comes first).
4+
5+
declare module '@edx/frontend-platform/i18n' {
6+
// eslint-disable-next-line import/no-extraneous-dependencies
7+
import { injectIntl as _injectIntl } from 'react-intl';
8+
/** @deprecated Use useIntl() hook instead. */
9+
export const injectIntl: typeof _injectIntl;
10+
/** @deprecated Use useIntl() hook instead. */
11+
export const intlShape: any;
12+
13+
// eslint-disable-next-line import/no-extraneous-dependencies
14+
export {
15+
createIntl,
16+
FormattedDate,
17+
FormattedTime,
18+
FormattedRelativeTime,
19+
FormattedNumber,
20+
FormattedPlural,
21+
FormattedMessage,
22+
defineMessages,
23+
IntlProvider,
24+
useIntl,
25+
} from 'react-intl';
26+
27+
// Other exports from the i18n module:
28+
export const configure: any;
29+
export const getPrimaryLanguageSubtag: (code: string) => string;
30+
export const getLocale: (locale?: string) => string;
31+
export const getMessages: any;
32+
export const isRtl: (locale?: string) => boolean;
33+
export const handleRtl: any;
34+
export const mergeMessages: any;
35+
export const LOCALE_CHANGED: any;
36+
export const LOCALE_TOPIC: any;
37+
export const getCountryList: any;
38+
export const getCountryMessages: any;
39+
export const getLanguageList: any;
40+
export const getLanguageMessages: any;
41+
}

src/mobile-header/MobileHeader.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import messages from '../Header.messages';
2121
import { MenuIcon } from '../Icons';
2222

2323
class MobileHeader extends React.Component {
24-
constructor(props) { // eslint-disable-line no-useless-constructor
24+
constructor(props) { // eslint-disable-line @typescript-eslint/no-useless-constructor
2525
super(props);
2626
}
2727

src/studio-header/BrandNav.test.jsx renamed to src/studio-header/BrandNav.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('BrandNav Component', () => {
3434
it('displays a link that navigates to studioBaseUrl', () => {
3535
render(<RootWrapper />);
3636

37-
const link = screen.getByRole('link');
37+
const link = screen.getByRole('link') as HTMLAnchorElement;
3838
expect(link.href).toBe(studioBaseUrl);
3939
});
4040
});
File renamed without changes.

src/studio-header/CourseLockUp.test.jsx renamed to src/studio-header/CourseLockUp.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const mockProps = {
1616

1717
const RootWrapper = (props) => (
1818
<MemoryRouter>
19-
<IntlProvider locale="en" messages={messages}>
19+
<IntlProvider locale="en" messages={{}}>
2020
<CourseLockUp {...props} />
2121
</IntlProvider>
2222
</MemoryRouter>
@@ -52,7 +52,8 @@ describe('CourseLockUp Component', () => {
5252
it('navigates to an absolute URL when clicked', () => {
5353
render(<RootWrapper {...mockProps} />);
5454

55-
const link = screen.getByTestId('course-lock-up-block');
55+
// FIXME: don't use testId - https://testing-library.com/docs/queries/about#priority
56+
const link = screen.getByTestId('course-lock-up-block') as HTMLAnchorElement;
5657
expect(link.href).toBe(mockProps.outlineLink);
5758
});
5859
});

0 commit comments

Comments
 (0)