Skip to content

Upgrade TypeScript from 4.5 to 4.8#6911

Merged
aduth merged 3 commits intomainfrom
aduth-upgrade-typescript
Sep 6, 2022
Merged

Upgrade TypeScript from 4.5 to 4.8#6911
aduth merged 3 commits intomainfrom
aduth-upgrade-typescript

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Sep 2, 2022

Why: Take advantage of the latest features and bug fixes.

Errors addressed after upgrade:

$ tsc
app/javascript/packages/normalize-yaml/index.js:20:29 - error TS2463: A binding pattern parameter cannot be optional in an implementation signature.

20 function normalize(content, { prettierConfig, exclude } = {}) {
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app/javascript/packages/secret-session-storage/index.ts:110:30 - error TS2345: Argument of type 'ArrayBuffer' is not assignable to parameter of type 'Uint8Array'.
  Type 'ArrayBuffer' is missing the following properties from type 'Uint8Array': BYTES_PER_ELEMENT, buffer, byteOffset, copyWithin, and 24 more.

110       return JSON.parse(ab2s(data));
                                 ~~~~

app/javascript/packages/secret-session-storage/index.ts:125:84 - error TS2345: Argument of type '(buffer: Uint8Array) => any' is not assignable to parameter of type '(value: ArrayBuffer, index: number, array: ArrayBuffer[]) => any'.
  Types of parameters 'buffer' and 'value' are incompatible.
    Type 'ArrayBuffer' is not assignable to type 'Uint8Array'.

125     sessionStorage.setItem(this.storageKey, JSON.stringify([encryptedData, iv].map(ab2s)));
                                                                                       ~~~~

app/javascript/packages/verify-flow/context/flow-context.tsx:27:31 - error TS2842: 'string' is an unused renaming of 'completionURL'. Did you intend to use it as a type annotation?

27   onComplete({ completionURL: string }): void;
                                 ~~~~~~

  app/javascript/packages/verify-flow/context/flow-context.tsx:27:39
    27   onComplete({ completionURL: string }): void;
                                             ~
    We can only write a type for 'completionURL' by adding a type for the entire parameter here.

app/javascript/packs/document-capture.jsx:130:7 - error TS2322: Type 'string[][]' is not assignable to type 'HeadersInit | undefined'.
  Type 'string[][]' is not assignable to type '[string, string][]'.
    Type 'string[]' is not assignable to type '[string, string]'.
      Target requires 2 element(s) but source may have fewer.

130       headers: /** @type {string[][]} */ ([csrf && ['X-CSRF-Token', csrf]].filter(Boolean)),
          ~~~~~~~

**Why**: Take advantage of the latest features and bug fixes.

changelog: Internal, Dependencies, Update dependencies to latest version
window.fetch(keepAliveEndpoint, {
method: 'POST',
headers: /** @type {string[][]} */ ([csrf && ['X-CSRF-Token', csrf]].filter(Boolean)),
headers: [csrf && ['X-CSRF-Token', csrf]].filter(Boolean) as [string, string][],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I snuck in a TypeScript file conversion as part of the pull request, but this line was the only change needed to satisfy the new errors. See the original commit 935b91d to see the change more clearly.

Comment on lines -19 to -35
/** @typedef {import('@18f/identity-i18n').I18n} I18n */

/**
* @typedef LoginGov
*
* @prop {Record<string,string>} assets
*/

/**
* @typedef LoginGovGlobals
*
* @prop {LoginGov} LoginGov
*/

/**
* @typedef {typeof window & LoginGovGlobals} DocumentCaptureGlobal
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice thing about native TypeScript is that the unused values are flagged, unlike JSDoc-based types.

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM

TypeScript 4.8 compat
@aduth aduth merged commit 4b13c4f into main Sep 6, 2022
@aduth aduth deleted the aduth-upgrade-typescript branch September 6, 2022 12:34
@zachmargolis zachmargolis mentioned this pull request Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants