Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update typescript to 5.3.3 #14407

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**/build/**
**/venv/**
.opentrons_config
**/tsconfig*.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescript-eslint/parser seems unable to parse tsconfig json files, so we're ignoring them


# prettier
**/package.json
Expand Down
31 changes: 29 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ module.exports = {
project: require('path').join(__dirname, 'tsconfig-eslint.json'),
},

extends: ['standard-with-typescript', 'plugin:react/recommended', 'prettier'],
extends: [
'standard-with-typescript',
'plugin:react/recommended',
'prettier',
'plugin:json/recommended',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out, without extending these rules we weren't actually linting json files in edge. so now we're actually linting json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downside: linting json via typescript-eslint/parser takes about an extra minute to run

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol fyi @sfoster1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],

plugins: ['react', 'react-hooks', 'json', 'jest', 'testing-library'],

Expand Down Expand Up @@ -50,7 +55,15 @@ module.exports = {
overrides: [
{
files: ['**/*.js'],
parser: '@babel/eslint-parser',
extends: ['plugin:@typescript-eslint/disable-type-checked'],
parserOptions: {
project: require('path').join(__dirname, 'tsconfig-eslint.json'),
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
},
},
{
// TODO(mc, 2021-03-18): remove to default these rules back to errors
Expand All @@ -65,6 +78,17 @@ module.exports = {
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'warn',
'@typescript-eslint/no-confusing-void-expression': 'warn',
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/non-nullable-type-assertion-style': 'warn',
'@typescript-eslint/await-thenable': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/unbound-method': 'warn',
'@typescript-eslint/consistent-generic-constructors': 'warn',
'@typescript-eslint/no-misused-promises': 'warn',
},
},
{
Expand All @@ -88,11 +112,14 @@ module.exports = {
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-confusing-void-expression': 'warn',
'node/handle-callback-err': 'off',
// TODO(mc, 2021-01-29): fix these and remove warning overrides
'jest/no-deprecated-functions': 'warn',
'jest/valid-title': 'warn',
'jest/no-conditional-expect': 'warn',
'jest/no-alias-methods': 'warn',
'jest/valid-describe-callback': 'warn',
},
},
{
Expand Down
12 changes: 7 additions & 5 deletions app-shell/src/protocol-storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export const getUnixTimeFromAnalysisPath = (analysisPath: string): number =>

export const getParsedAnalysisFromPath = (
analysisPath: string
): ProtocolAnalysisOutput => {
): ProtocolAnalysisOutput | undefined => {
try {
return fse.readJsonSync(analysisPath)
} catch (error) {
return createFailedAnalysis(
error?.message ?? 'protocol analysis file cannot be parsed'
)
const errorMessage =
error instanceof Error && error?.message != null
? error.message
: 'protocol analysis file cannot be parsed'
return createFailedAnalysis(errorMessage)
}
}

Expand Down Expand Up @@ -135,7 +137,7 @@ export const fetchProtocols = (
}, null)
const mostRecentAnalysis =
mostRecentAnalysisFilePath != null
? getParsedAnalysisFromPath(mostRecentAnalysisFilePath)
? getParsedAnalysisFromPath(mostRecentAnalysisFilePath) ?? null
: null

return {
Expand Down
4 changes: 3 additions & 1 deletion app-shell/src/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ async function usbListener(
statusText: response.statusText,
}
} catch (e) {
console.log(`axios request error ${e?.message ?? 'unknown'}`)
if (e instanceof Error) {
console.log(`axios request error ${e?.message ?? 'unknown'}`)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('syncSystemTimeEpic', () => {
)

expect(
// @ts-expect-error
Math.abs(differenceInSeconds(new Date(), parseISO(updatedTime)))
).toBe(0)
})
Expand Down
1 change: 1 addition & 0 deletions app/src/redux/robot-update/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface RobotUpdateInfoPayload {
version: string | null
target: RobotUpdateTarget
releaseNotes: string | null
force?: boolean
}

export interface RobotUpdateInfo {
Expand Down
16 changes: 8 additions & 8 deletions components/src/primitives/Btn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const Btn: BtnComponent = styled.button
*
* @component
*/
export const PrimaryBtn: BtnComponent = styled(Btn)`
export const PrimaryBtn = styled(Btn)`
${BUTTON_VARIANT_STYLE}
background-color: ${Styles.C_DARK_GRAY};
color: ${Styles.C_WHITE};
Expand Down Expand Up @@ -96,7 +96,7 @@ export const PrimaryBtn: BtnComponent = styled(Btn)`
*
* @component
*/
export const SecondaryBtn: BtnComponent = styled(Btn)`
export const SecondaryBtn = styled(Btn)`
${BUTTON_VARIANT_STYLE}
background-color: ${Styles.C_WHITE};
border-width: ${Styles.BORDER_WIDTH_DEFAULT};
Expand Down Expand Up @@ -125,7 +125,7 @@ export const SecondaryBtn: BtnComponent = styled(Btn)`
*
* @component
*/
export const NewPrimaryBtn: BtnComponent = styled(PrimaryBtn)`
export const NewPrimaryBtn = styled(PrimaryBtn)`
background-color: ${Styles.C_BLUE};
color: ${Styles.C_WHITE};

Expand Down Expand Up @@ -155,7 +155,7 @@ export const NewPrimaryBtn: BtnComponent = styled(PrimaryBtn)`
*
* @component
*/
export const NewSecondaryBtn: BtnComponent = styled(SecondaryBtn)`
export const NewSecondaryBtn = styled(SecondaryBtn)`
background-color: ${Styles.C_WHITE};
color: ${Styles.C_BLUE};

Expand Down Expand Up @@ -190,7 +190,7 @@ export const NewSecondaryBtn: BtnComponent = styled(SecondaryBtn)`
*
* @component
*/
export const NewAlertPrimaryBtn: BtnComponent = styled(NewPrimaryBtn)`
export const NewAlertPrimaryBtn = styled(NewPrimaryBtn)`
background-color: ${Styles.C_ERROR_DARK};

&:hover,
Expand All @@ -210,7 +210,7 @@ export const NewAlertPrimaryBtn: BtnComponent = styled(NewPrimaryBtn)`
*
* @component
*/
export const NewAlertSecondaryBtn: BtnComponent = styled(NewSecondaryBtn)`
export const NewAlertSecondaryBtn = styled(NewSecondaryBtn)`
color: ${Styles.C_ERROR_DARK};

&:hover,
Expand All @@ -230,7 +230,7 @@ export const NewAlertSecondaryBtn: BtnComponent = styled(NewSecondaryBtn)`
*
* @component
*/
export const LightSecondaryBtn: BtnComponent = styled(SecondaryBtn)`
export const LightSecondaryBtn = styled(SecondaryBtn)`
background-color: ${Styles.C_TRANSPARENT};
color: ${Styles.C_WHITE};

Expand All @@ -257,6 +257,6 @@ export const LightSecondaryBtn: BtnComponent = styled(SecondaryBtn)`
*
* @component
*/
export const TertiaryBtn: BtnComponent = styled(LightSecondaryBtn)`
export const TertiaryBtn = styled(LightSecondaryBtn)`
border-width: 0;
`
6 changes: 3 additions & 3 deletions components/src/primitives/style-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pick from 'lodash/pick'

import * as Types from './types'
import type * as Types from './types'

import type { CSSObject } from 'styled-components'

Expand Down Expand Up @@ -164,8 +164,8 @@ const layoutStyles = (props: Types.StyleProps): CSSObject => {
const { size, ...styles } = pick(props, LAYOUT_PROPS) as CSSObject

if (size != null) {
styles.width = styles.width ?? (size as typeof styles.width)
styles.height = styles.height ?? (size as typeof styles.height)
styles.width = styles.width ?? ((size as unknown) as typeof styles.width)
styles.height = styles.height ?? ((size as unknown) as typeof styles.height)
}

return styles
Expand Down
11 changes: 7 additions & 4 deletions components/src/testing/utils/renderWithProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Provider } from 'react-redux'
import { render, RenderResult } from '@testing-library/react'
import { createStore } from 'redux'

import type { Store } from 'redux'
import type { PreloadedState, Store } from 'redux'
import type { RenderOptions } from '@testing-library/react'

export interface RenderWithProvidersOptions<State> extends RenderOptions {
Expand All @@ -20,11 +20,14 @@ export function renderWithProviders<State>(
options?: RenderWithProvidersOptions<State>
): [RenderResult, Store<State>] {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const { initialState = {} as State, i18nInstance = null } = options || {}
const { initialState = {}, i18nInstance = null } = options || {}

const store: Store<State> = createStore(jest.fn(), initialState)
const store: Store<State> = createStore(
jest.fn(),
initialState as PreloadedState<State>
)
store.dispatch = jest.fn()
store.getState = jest.fn(() => initialState)
store.getState = jest.fn(() => initialState) as () => State

const queryClient = new QueryClient()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import { Formik, FormikConfig } from 'formik'
export const wrapInFormik = <Values,>(
component: JSX.Element,
formikConfig: FormikConfig<Values>
// @ts-expect-error
): JSX.Element => <Formik {...formikConfig}>{() => component}</Formik>
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ const partialCast = <TKey extends keyof LabwareFields>(
// ignore them. We can sniff if something is a Yup error by checking error.name.
// See https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
// and https://github.com/formium/formik/blob/2d613c11a67b1c1f5189e21b8d61a9dd8a2d0a2e/packages/formik/src/Formik.tsx
if (error.name !== 'ValidationError' && error.name !== 'TypeError') {
if (
error instanceof Error &&
error.name !== 'ValidationError' &&
error.name !== 'TypeError'
) {
// TODO(IL, 2021-05-19): why are missing values for required fields giving TypeError instead of ValidationError?
// Is this partial schema (from `pick`) not handing requireds correctly??
throw error
Expand Down
10 changes: 6 additions & 4 deletions labware-library/src/labware-creator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@
parsedLabwareDef = JSON.parse(result as string)
} catch (error) {
console.error(error)
setImportError({
key: 'INVALID_JSON_FILE',
messages: [error.message],
})
if (error instanceof Error) {
setImportError({

Check warning on line 202 in labware-library/src/labware-creator/index.tsx

View check run for this annotation

Codecov / codecov/patch

labware-library/src/labware-creator/index.tsx#L202

Added line #L202 was not covered by tests
key: 'INVALID_JSON_FILE',
messages: [error.message],
})
}
return
}

Expand Down
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"engines": {
"node": "^18.19.0"
},
"resolutions": {
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.cd77847.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/eslint-parser": "^7.12.1",
Expand Down Expand Up @@ -68,8 +71,8 @@
"@types/react-router-dom": "5.3.3",
"@types/redux-mock-store": "^1.0.2",
"@types/semver": "^7.3.6",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"ajv": "6.12.3",
"aws-sdk": "^2.493.0",
"babel-jest": "^26.6.3",
Expand All @@ -89,18 +92,18 @@
"download": "8.0.0",
"electron": "27.0.0",
"electron-builder": "24.0.0",
"eslint": "^7.22.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard-with-typescript": "^20.0.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jest": "^24.3.2",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-testing-library": "^6.2.0",
"express": "^4.16.4",
Expand Down Expand Up @@ -156,7 +159,7 @@
"stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.10.0",
"terser-webpack-plugin": "^2.3.5",
"typescript": "4.1.3",
"typescript": "5.3.3",
"url-loader": "^2.1.0",
"wait-on": "^4.0.2",
"webpack": "^4.41.6",
Expand Down
20 changes: 11 additions & 9 deletions protocol-designer/src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@
return rootReducer(resetState, action)
} catch (e) {
console.error(e)
// something in the reducers went wrong, show it to the user for bug report
return rootReducer(
state,
fileUploadMessage({
isError: true,
errorType: 'INVALID_JSON_FILE',
errorMessage: e.message,
})
)
if (e instanceof Error) {
// something in the reducers went wrong, show it to the user for bug report
return rootReducer(

Check warning on line 52 in protocol-designer/src/configureStore.ts

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/configureStore.ts#L52

Added line #L52 was not covered by tests
state,
fileUploadMessage({
isError: true,
errorType: 'INVALID_JSON_FILE',
errorMessage: e.message,
})
)
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions protocol-designer/src/labware-defs/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@
parsedLabwareDef = JSON.parse((result as any) as string)
} catch (error) {
console.error(error)
return dispatch(
labwareUploadMessage({
messageType: 'INVALID_JSON_FILE',
errorText: error.message,
})
)
if (error instanceof Error) {
return dispatch(

Check warning on line 124 in protocol-designer/src/labware-defs/actions.ts

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/labware-defs/actions.ts#L124

Added line #L124 was not covered by tests
labwareUploadMessage({
messageType: 'INVALID_JSON_FILE',
errorText: error.message,
})
)
}
}

const valid: boolean | PromiseLike<any> =
Expand Down
4 changes: 3 additions & 1 deletion protocol-designer/src/load-file/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
parsedProtocol && dispatch(loadFileAction(parsedProtocol))
} catch (error) {
console.error(error)
fileError('INVALID_JSON_FILE', error.message)
if (error instanceof Error) {
fileError('INVALID_JSON_FILE', error.message)

Check warning on line 69 in protocol-designer/src/load-file/actions.ts

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/load-file/actions.ts#L69

Added line #L69 was not covered by tests
}
}
}

Expand Down
Loading
Loading