Skip to content

Commit 03dd8ce

Browse files
committed
Add type annotations to all React component state members.
I'm not really sure why, but without this, TypeScript thinks that the state can only have the values that it sees in the initialization value. It also doesn't complain if setState is called with values that don't match the type it inferred for the state member. It needs to know that this.state can have other values than the initial value if we want to avoid false positives from '@typescript-eslint/no-unnecessary-condition'.
1 parent 22a3742 commit 03dd8ce

35 files changed

Lines changed: 37 additions & 37 deletions

src/components/app/CompareHome.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type State = {
2323
};
2424

2525
class CompareHomeImpl extends PureComponent<Props, State> {
26-
override state = { profile1: '', profile2: '' };
26+
override state: State = { profile1: '', profile2: '' };
2727

2828
handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
2929
const { name, value } = event.target;

src/components/app/FooterLinks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class FooterLinks extends PureComponent<{}, State> {
1515
this.setState({ hide: true });
1616
};
1717

18-
override state = {
18+
override state: State = {
1919
hide: false,
2020
};
2121

src/components/app/Home.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ActionButtons extends React.PureComponent<
5454
> {
5555
_fileInput: HTMLInputElement | null = null;
5656

57-
override state = {
57+
override state: ActionButtonsState = {
5858
isLoadFromUrlPressed: false,
5959
};
6060

@@ -129,7 +129,7 @@ class LoadFromUrl extends React.PureComponent<
129129
LoadFromUrlProps,
130130
LoadFromUrlState
131131
> {
132-
override state = {
132+
override state: LoadFromUrlState = {
133133
value: '',
134134
};
135135

src/components/app/KeyboardShortcut.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type State = {
2323
* Display a list of shortcuts that overlays the screen.
2424
*/
2525
export class KeyboardShortcut extends React.PureComponent<Props, State> {
26-
override state = {
26+
override state: State = {
2727
isOpen: false,
2828
// The eslint error is a false positive due to how it's used, see the line:
2929
// `focusAfterClosed.focus()`

src/components/app/ListOfPublishedProfiles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PublishedProfile extends React.PureComponent<
4949
PublishedProfileProps,
5050
PublishedProfileState
5151
> {
52-
override state = {
52+
override state: PublishedProfileState = {
5353
confirmDialogIsOpen: false,
5454
};
5555

@@ -162,7 +162,7 @@ type State = {
162162
export class ListOfPublishedProfiles extends PureComponent<Props, State> {
163163
_isMounted = false;
164164

165-
override state = {
165+
override state: State = {
166166
uploadedProfileInformationList: null,
167167
};
168168

src/components/app/MenuButtons/MetaInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Props = ConnectedProps<{}, StateProps, DispatchProps>;
5555
* This component formats the profile's meta information into a dropdown panel.
5656
*/
5757
class MetaInfoPanelImpl extends React.PureComponent<Props, State> {
58-
override state = { showsMoreInfo: false };
58+
override state: State = { showsMoreInfo: false };
5959

6060
/**
6161
* This method provides information about the symbolication status, and a button

src/components/app/MenuButtons/Permalink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class MenuButtonsPermalink extends React.PureComponent<Props, State> {
3030
this._permalinkTextField = elem;
3131
};
3232

33-
override state = {
33+
override state: State = {
3434
fullUrl: '',
3535
shortUrl: '',
3636
};

src/components/app/ProfileName.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type State = {
3737
* state), and then when active, it switches to an input, which is only fixed in size.
3838
*/
3939
class ProfileNameImpl extends React.PureComponent<Props, State> {
40-
override state = {
40+
override state: State = {
4141
focusedWithKey: null,
4242
focusGeneration: 0,
4343
};

src/components/js-tracer/Canvas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const ROW_LABEL_OFFSET_LEFT: CssPixels = 5;
9090
const FONT_SIZE: CssPixels = 10;
9191

9292
class JsTracerCanvasImpl extends React.PureComponent<Props, State> {
93-
override state = {
93+
override state: State = {
9494
hasFirstDraw: false,
9595
};
9696
_textMeasurement: TextMeasurement | null = null;

src/components/js-tracer/Chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class JsTracerChartLoader extends React.PureComponent<
175175
ChartLoaderProps,
176176
ChartLoaderState
177177
> {
178-
override state = {
178+
override state: ChartLoaderState = {
179179
// The loader needs to be mounted before rendering the chart, as it has expensive
180180
// selectors.
181181
readyToRenderExpensiveChart: false,

0 commit comments

Comments
 (0)