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

FEI-4957.4: Run codemod to convert files to TypeScript #526

Merged
merged 2 commits into from
Feb 16, 2023

Conversation

kevinbarabash
Copy link
Contributor

@kevinbarabash kevinbarabash commented Feb 14, 2023

Summary:

This changeset was generated using the follow commands:

  • cd ../flow-to-typescript-codemod
  • yarn typescriptify convert -p ../wonder-stuff --write --delete
  • // manually change 'export {* as jest} from "jest"' to be 'export * as jest from "jest"' in wonder-stuff
  • yarn typescriptify fix --autoSuppressErrors --jiraSlug FEI-5011 -p ../wonder-stuff --config ../wonder-stuff/tsconfig.json
  • // manually rename prettierrc.ts to prettierrc.js
  • cd ../wonder-stuff
  • yarn format

The next PR will fix all the TypeScript errors

Issue: FEI-4957

Test plan:

  • yarn tsc --noEmit, see a bunch of errors
Found 24 errors in 7 files.

Errors  Files
     2  packages/wonder-stuff-i18n/src/utils/emoji-for-locale.ts:46
    10  packages/wonder-stuff-sentry/src/normalize-sentry-data.ts:34
     2  packages/wonder-stuff-server-google/src/start-server.ts:26
     1  packages/wonder-stuff-server/src/middleware/default-error-logging.ts:18
     1  packages/wonder-stuff-server/src/middleware/default-request-logging.ts:18
     4  packages/wonder-stuff-server/src/start-server.ts:37
     4  packages/wonder-stuff-server/src/types.ts:1

@kevinbarabash kevinbarabash self-assigned this Feb 14, 2023
@changeset-bot
Copy link

changeset-bot bot commented Feb 14, 2023

🦋 Changeset detected

Latest commit: 7fd0012

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@khanacademy/wonder-stuff-server-google Major
@khanacademy/wonder-stuff-testing Major
@khanacademy/wonder-stuff-sentry Minor
@khanacademy/wonder-stuff-server Major
@khanacademy/eslint-config Minor
@khanacademy/wonder-stuff-core Minor
@khanacademy/wonder-stuff-i18n Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@khan-actions-bot khan-actions-bot requested a review from a team February 14, 2023 14:56
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Feb 14, 2023

Gerald

Required Reviewers
  • @Khan/frontend-infra for changes to .changeset/fifty-grapes-guess.md, packages/eslint-config-khan/.prettierrc.js, packages/wonder-stuff-core/src/build-caused-by-message.ts, packages/wonder-stuff-core/src/clone-metadata.ts, packages/wonder-stuff-core/src/clone.ts, packages/wonder-stuff-core/src/error-info.ts, packages/wonder-stuff-core/src/errors-from-error.ts, packages/wonder-stuff-core/src/errors.ts, packages/wonder-stuff-core/src/get-kind-from-error.ts, packages/wonder-stuff-core/src/get-original-stack-from-error.ts, packages/wonder-stuff-core/src/index.ts, packages/wonder-stuff-core/src/kind-error.ts, packages/wonder-stuff-core/src/safe-stringify.ts, packages/wonder-stuff-core/src/truncate-middle.ts, packages/wonder-stuff-core/src/types.ts, packages/wonder-stuff-i18n/src/index.ts, packages/wonder-stuff-sentry/src/collate-sentry-data.ts, packages/wonder-stuff-sentry/src/default-kind-error-data-options.ts, packages/wonder-stuff-sentry/src/empty-sentry-data.ts, packages/wonder-stuff-sentry/src/get-sentry-data-from-error.ts, packages/wonder-stuff-sentry/src/index.ts, packages/wonder-stuff-sentry/src/is-reserved-context-property.ts, packages/wonder-stuff-sentry/src/is-reserved-tag-key.ts, packages/wonder-stuff-sentry/src/is-tag-key-valid.ts, packages/wonder-stuff-sentry/src/kind-error-data.ts, packages/wonder-stuff-sentry/src/kind-sentry-error.ts, packages/wonder-stuff-sentry/src/normalize-sentry-data.ts, packages/wonder-stuff-sentry/src/sentry-data-reducer.ts, packages/wonder-stuff-sentry/src/truncate-tag-value.ts, packages/wonder-stuff-sentry/src/types.ts, packages/wonder-stuff-server/src/create-logger.ts, packages/wonder-stuff-server/src/errors.ts, packages/wonder-stuff-server/src/get-agent-for-url.ts, packages/wonder-stuff-server/src/get-logger.ts, packages/wonder-stuff-server/src/get-logging-transport.ts, packages/wonder-stuff-server/src/get-request-logger.ts, packages/wonder-stuff-server/src/get-runtime-mode.ts, packages/wonder-stuff-server/src/index.ts, packages/wonder-stuff-server/src/root-logger.ts, packages/wonder-stuff-server/src/start-server.ts, packages/wonder-stuff-server/src/types.ts, packages/wonder-stuff-server-google/src/add-app-engine-middleware.ts, packages/wonder-stuff-server-google/src/get-app-engine-info.ts, packages/wonder-stuff-server-google/src/get-app-engine-request-id.ts, packages/wonder-stuff-server-google/src/get-default-log-metadata.ts, packages/wonder-stuff-server-google/src/get-delta.ts, packages/wonder-stuff-server-google/src/index.ts, packages/wonder-stuff-server-google/src/setup-integrations.ts, packages/wonder-stuff-server-google/src/start-server.ts, packages/wonder-stuff-server-google/src/trace-impl.ts, packages/wonder-stuff-server-google/src/trace.ts, packages/wonder-stuff-server-google/src/types.ts, packages/wonder-stuff-testing/src/data-factory-for.ts, packages/wonder-stuff-testing/src/index.ts, packages/wonder-stuff-core/src/__tests__/build-caused-by-message.test.ts, packages/wonder-stuff-core/src/__tests__/clone-metadata.test.ts, packages/wonder-stuff-core/src/__tests__/clone.test.ts, packages/wonder-stuff-core/src/__tests__/entries.flowtest.ts, packages/wonder-stuff-core/src/__tests__/entries.test.ts, packages/wonder-stuff-core/src/__tests__/error-info.test.ts, packages/wonder-stuff-core/src/__tests__/errors-from-error.test.ts, packages/wonder-stuff-core/src/__tests__/errors.test.ts, packages/wonder-stuff-core/src/__tests__/get-kind-from-error.test.ts, packages/wonder-stuff-core/src/__tests__/get-original-stack-from-error.test.ts, packages/wonder-stuff-core/src/__tests__/keys.flowtest.ts, packages/wonder-stuff-core/src/__tests__/keys.test.ts, packages/wonder-stuff-core/src/__tests__/kind-error.test.ts, packages/wonder-stuff-core/src/__tests__/safe-stringify.test.ts, packages/wonder-stuff-core/src/__tests__/truncate-middle.test.ts, packages/wonder-stuff-core/src/__tests__/values.flowtest.ts, packages/wonder-stuff-core/src/__tests__/values.test.ts, packages/wonder-stuff-i18n/src/bin/all-i18n-strings.ts, packages/wonder-stuff-i18n/src/bin/gen-potfile.ts, packages/wonder-stuff-i18n/src/plugins/i18n-plugin.ts, packages/wonder-stuff-i18n/src/utils/emoji-for-locale.ts, packages/wonder-stuff-i18n/src/utils/extract-i18n.ts, packages/wonder-stuff-i18n/src/utils/i18n-utils.ts, packages/wonder-stuff-i18n/src/utils/localize-file.ts, packages/wonder-stuff-i18n/src/utils/pofile-utils.ts, packages/wonder-stuff-sentry/src/__tests__/collate-sentry-data.test.ts, packages/wonder-stuff-sentry/src/__tests__/get-sentry-data-from-error.test.ts, packages/wonder-stuff-sentry/src/__tests__/is-reserved-context-property.test.ts, packages/wonder-stuff-sentry/src/__tests__/is-reserved-tag-key.test.ts, packages/wonder-stuff-sentry/src/__tests__/is-tag-key-valid.test.ts, packages/wonder-stuff-sentry/src/__tests__/kind-error-data.test.ts, packages/wonder-stuff-sentry/src/__tests__/kind-sentry-error.test.ts, packages/wonder-stuff-sentry/src/__tests__/normalize-sentry-data.test.ts, packages/wonder-stuff-sentry/src/__tests__/sentry-data-reducer.test.ts, packages/wonder-stuff-sentry/src/__tests__/truncate-tag-value.test.ts, packages/wonder-stuff-server/src/__tests__/create-logger.test.ts, packages/wonder-stuff-server/src/__tests__/get-agent-for-url.test.ts, packages/wonder-stuff-server/src/__tests__/get-logger.test.ts, packages/wonder-stuff-server/src/__tests__/get-logging-transport.test.ts, packages/wonder-stuff-server/src/__tests__/get-request-logger.test.ts, packages/wonder-stuff-server/src/__tests__/get-runtime-mode.test.ts, packages/wonder-stuff-server/src/__tests__/root-logger.test.ts, packages/wonder-stuff-server/src/__tests__/start-server.test.ts, packages/wonder-stuff-server/src/middleware/default-error-logging.ts, packages/wonder-stuff-server/src/middleware/default-request-logging.ts, packages/wonder-stuff-server/src/middleware/index.ts, packages/wonder-stuff-server-google/src/__tests__/add-app-engine-middleware.test.ts, packages/wonder-stuff-server-google/src/__tests__/get-app-engine-info.test.ts, packages/wonder-stuff-server-google/src/__tests__/get-appengine-request-id.test.ts, packages/wonder-stuff-server-google/src/__tests__/get-delta.test.ts, packages/wonder-stuff-server-google/src/__tests__/setup-integrations.test.ts, packages/wonder-stuff-server-google/src/__tests__/start-server.test.ts, packages/wonder-stuff-server-google/src/__tests__/trace-impl.test.ts, packages/wonder-stuff-server-google/src/__tests__/trace.test.ts, packages/wonder-stuff-server-google/src/middleware/make-app-engine-request-id-middleware.ts, packages/wonder-stuff-testing/src/__tests__/data-factory-for.test.ts, packages/wonder-stuff-testing/src/jest/index.ts, packages/wonder-stuff-testing/src/jest/isolate-modules.ts, packages/wonder-stuff-testing/src/jest/wait.ts, packages/wonder-stuff-core/src/__tests__/__snapshots__/build-caused-by-message.test.ts.snap, packages/wonder-stuff-core/src/__tests__/__snapshots__/errors-from-error.test.ts.snap, packages/wonder-stuff-core/src/__tests__/__snapshots__/kind-error.test.ts.snap, packages/wonder-stuff-i18n/src/plugins/__tests__/i18n-plugin.test.ts, packages/wonder-stuff-i18n/src/utils/__tests__/emoji-for-locale.test.ts, packages/wonder-stuff-i18n/src/utils/__tests__/extract-i18n.test.ts, packages/wonder-stuff-i18n/src/utils/__tests__/i18n-utils.test.ts, packages/wonder-stuff-i18n/src/utils/__tests__/localize-file.test.ts, packages/wonder-stuff-i18n/src/utils/__tests__/pofile-utils.test.ts, packages/wonder-stuff-sentry/src/__tests__/__snapshots__/kind-error-data.test.ts.snap, packages/wonder-stuff-server/src/__tests__/__snapshots__/get-logging-transport.test.ts.snap, packages/wonder-stuff-server/src/middleware/__tests__/default-error-logging.test.ts, packages/wonder-stuff-server/src/middleware/__tests__/default-request-logging.test.ts, packages/wonder-stuff-server-google/src/__tests__/__snapshots__/trace-impl.test.ts.snap, packages/wonder-stuff-server-google/src/middleware/__tests__/make-app-engine-request-id-middleware.test.ts, packages/wonder-stuff-testing/src/jest/__tests__/isolate-modules.test.ts, packages/wonder-stuff-testing/src/jest/__tests__/wait.test.ts, packages/wonder-stuff-testing/src/jest/internal/assert-jest.ts, packages/wonder-stuff-testing/src/jest/internal/is-running-in-jest.ts, packages/wonder-stuff-testing/src/jest/internal/unverified-wait.ts, packages/wonder-stuff-testing/src/jest/internal/verify-real-timers.ts, packages/wonder-stuff-testing/src/jest/internal/__tests__/assert-jest.test.ts, packages/wonder-stuff-testing/src/jest/internal/__tests__/unverified-wait.test.ts, packages/wonder-stuff-testing/src/jest/internal/__tests__/verify-real-timers.test.ts

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

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

Amazing - that's really all the errors that remain? So few!

@jeresig
Copy link
Member

jeresig commented Feb 14, 2023

@kevinbarabash If you don't have a task for it yet, you're going to want to add a TS linter step that runs on a repo (probably have it check to see if a flowconfig exists, then run flow, and if a tsconfig exists, run TypeScript)

@kevinbarabash
Copy link
Contributor Author

@kevinbarabash If you don't have a task for it yet, you're going to want to add a TS linter step that runs on a repo (probably have it check to see if a flowconfig exists, then run flow, and if a tsconfig exists, run TypeScript)

I don't have anything in the migration guide about setting up GitHub actions. I'll add a section to call that out after I finish converting this repo. It's all going to be under the same task.

Copy link
Member

@somewhatabstract somewhatabstract left a comment

Choose a reason for hiding this comment

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

Good to see the automation do so much work for us. It's a shame that so many error suppressions get added when a judicial use of any or mixed would fix it (specifically regarding tests).

I am a little concerned by the suppressions in some of the more strongly-typed functions like clone.js, but we can revisit these things post-conversion, and they seem to be specific to the internals rather than leaking into the external representation, so no big deal.


// Act
const result = cloneMetadata(metadata);
// @ts-expect-error [FEI-5011] - TS2540 - Cannot assign to 'string' because it is a read-only property.
Copy link
Member

Choose a reason for hiding this comment

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

note: It's a shame we have all these error suppressions instead of just a judicial use of any on the variable from the beginning. Since these are test files, that feels like the right thing. Of course, that's manual work and would really take time, so I'm not requesting a change here. Just lamenting the tech debt/mess that is left behind.

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 expect there will be quite a bit of post-conversion work to improve our types.

Comment on lines 37 to +39
const originalValue = {
array: [1, 2, 3],
};
} as const;
Copy link
Member

Choose a reason for hiding this comment

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

question: What is as const for? Why is it needed if the variable is already const? Is it because TS demands that both sides of the = are const'd?

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'm not sure why the tool adds as const in so many places. We could change that behavior. as const in this context changes the type that is inferred for the object literal. With as const, it's inferred as precisely {array: [1, 2, 3]} whereas without it, it's inferred as {array: number[]}. TS playground example

@kevinbarabash
Copy link
Contributor Author

I am a little concerned by the suppressions in some of the more strongly-typed functions like clone.js, but we can revisit these things post-conversion, and they seem to be specific to the internals rather than leaking into the external representation, so no big deal.

I think we might be able to solve this with conditional types to help feed more accurate type info through the body of the function so that we don't need the // @ts-expect-error comments.

@kevinbarabash kevinbarabash merged commit 4538fa2 into main Feb 16, 2023
@kevinbarabash kevinbarabash deleted the fei-4957.4 branch February 16, 2023 16:54
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.

4 participants