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: use import type syntax #17864

Merged
merged 16 commits into from
Aug 24, 2021
Merged

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Aug 24, 2021

  • Closes N/A

User facing changelog

Additional details

I added the importsNotUsedAsValues rule to our ts/tsconfig.json. This enforces than type-only imports be written using the new import type syntax. Read about that rule here.

The reason this is useful is a lot of the newer ESM based build tools, like Vite, sometimes have problems trying to import types from TypeScript code designed to be used on the server. It will help future proof us.

For example in the unified feature branch ("launchpad"), which is developed using Vite, I may want to import an interface from server/lib/project-base.ts. That file also imports some Node.js only modules, like fs. If you do import { ProjectBase } from '@packages/server/lib/project-base.ts, it will error out, since Vite attempts to import the entire file to the browser, including the Node.js-only modules, like fs.

`import type { ProjectBase } from '...' works correctly - Vite is able to extract the type, and ignore the actual implementation code. No side effects 😎

Another potential benefit is the TS compiler can likely do some optimizations if it just importing a file for type definitions, not actual runtime code.

There's no real downside to the new import type syntax, so I just went ahead and added it to the entire code base. VS Code can even automatically do the correct import for you, since we have the rule in tsconfig.json.

How has the user experience changed?

N/A

PR Tasks

  • Have tests been added/updated?
  • Has the original issue or this PR been tagged with a release in ZenHub?
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@lmiller1990 lmiller1990 requested a review from a team as a code owner August 24, 2021 06:18
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 24, 2021

Thanks for taking the time to open a PR!

@lmiller1990 lmiller1990 removed the request for review from a team August 24, 2021 06:19
@cypress
Copy link

cypress bot commented Aug 24, 2021



Test summary

452 0 6 0Flakiness 0


Run details

Project cypress
Status Passed
Commit d745ca2
Started Aug 24, 2021 4:06 PM
Ended Aug 24, 2021 4:15 PM
Duration 08:56 💡
OS Linux Debian - 10.9
Browser Electron 91

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 changed the title chore: use import type across chore: use import type syntax across entire repo Aug 24, 2021
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

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

Looks good.

@jennifer-shehane
Copy link
Member

@lmiller1990 Seems to be quite a bit of failures in this branch. Could you look into those?

@lmiller1990
Copy link
Contributor Author

@jennifer-shehane actually just reporter is failing, I think the rest is flake -- gimme an hour. Thanks for the quick response.

@lmiller1990
Copy link
Contributor Author

@jennifer-shehane 1 hour has passed, as promised we are all green ✅

tgriesser
tgriesser previously approved these changes Aug 24, 2021
Copy link
Member

@tgriesser tgriesser left a comment

Choose a reason for hiding this comment

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

This is great work, thanks for doing this @lmiller1990!

Copy link
Member

@tgriesser tgriesser left a comment

Choose a reason for hiding this comment

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

Great, let's merge as-is and revisit for any other packages it's missing on (reporter, ui-components, etc.)

Copy link
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

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

TIL about import type. Not sure what's up with semantic commit/percy checks...

@lmiller1990 lmiller1990 changed the title chore: use import type syntax across entire repo chore: use import type syntax Aug 24, 2021
@lmiller1990 lmiller1990 merged commit ab401ec into develop Aug 24, 2021
tgriesser added a commit that referenced this pull request Sep 1, 2021
…p-gui-gql-stitching

* unified-desktop-gui:
  fix: rename testApolloClient -> testUrqlClient, add apollo.config.js (#17948)
  feat(launchpad): detect if runner is set up and change UI accordingly (#17934)
  rebuild yarn lock
  chore: remove skipLibCheck, re-add vue-tsc, fix types (#17924)
  fix: ensure @headlessui/vue is bundled
  chore(graphql): make tsconfig more strict (#17909)
  run vite during watch
  fix: source maps while developing electron
  rebuild schema w/o JS files
  make constant more generic
  remove hanging tests
  allow larger artifacts
  comment out flaky test
  fix typing errors
  make graphql tsconfig more minimal
  chore: use `import type` syntax (#17864)
  remove browser-specific `beforeinput` checks (send in firefox) (#17820)
  fix(types): Update title method options type (#17781)
  fix(deps): update dependency @cypress/request to v2.88.6 🌟 (#17813)
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