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

TypeScript strict mode support + docs #5491

Merged
merged 83 commits into from
Jul 25, 2022

Conversation

dac09
Copy link
Contributor

@dac09 dac09 commented May 10, 2022

Background

If you turn on TypeScript strict mode, (modify tsconfig.json)

{
  "compilerOptions": {
    "noEmit": true,
    "allowJs": true,
+    "strict": true,

Redwood projects currently have a bunch of errors, with no clear path to a solution.

This PR is a combination of documentation, exporting and adding more types so that users opting-in to strict mode can have an error free project. Note that we are not enabling strict mode by default.

Changes in this PR

Generate stricter Resolver definitions in strict mode

  • When strict mode is turned on, make "args" of each of the resolvers (i.e. service functions) non-optional
  • Document changes to service tests to remove errors

src/lib/auth.ts

  • Documentation on how to get rid of the errors related to roles checks in src/lib/auth
  • Add types for getCurrentUser for non-dbAuth - this really is too hairy

dbAuth

  • Make DbAuthOptions and DbAuthSession available for users to import in their project.
  • Updates default generated templates in src/lib/auth and src/functions/auth to use these types
  • Allow generics, so the "user" in dbAuth can be typed
  • Documentation on how to use the generics
  • Add a line to setup auth dbAuth output on "using dbAuth with TS" generator output is already too verbose

Relation resolvers
When you have a model with a relation, and you generate the sdl or service with the --crud flag, relational resolvers are generated.

  • Changes the generator templates to use optional chaining to access gqlArgs.
    Reasoning:
    a) Although these are resolvers, they can be used outside the graphql context - where gqlArgs aren't passed.
    b) The alternative is to ask users to modify all their service tests. Its ugly and confusing and unnecessary.
  • Update graphql resolver docs

Prisma vs Graphql null types

Avoid optional resolvers types
This is a codegen config change (see graphqlCodegen.ts)

  • Make generated Resolver types non-optional, so they do not complain in strict mode

Improve return type of Scenarios

  • Expose ScenarioData type that lets you define exactly what the output of a scenario is
  • Add backlink here to scenario typing docs

Service tests with chained calls

  • Change template for service/scenario tests to tell TS to pipe down

Prisma findUnique return types
❌ No solution, just have to document

Closes #5481
Closes #5463
Closes #5261

dac09 added 4 commits May 9, 2022 16:23
…ctmode-gen

* 'main' of github.com:redwoodjs/redwood:
  Update yarn.lock
  fix(deps): update graphql-tools monorepo (redwoodjs#5487)
  v1.3.2
  Update yarn.lock
  fix: Run dedupe during upgrade on yarn 3 (redwoodjs#5458)
  Fix/ts resolvers type (redwoodjs#5437)
  fix(deps): update dependency graphql to v16.5.0 (redwoodjs#5488)
  fixed typo of roll to role (redwoodjs#5484)
  fix(deps): update typescript-eslint monorepo to v5.23.0 (redwoodjs#5489)
  chore(deps): update dependency cypress to v9.6.1 (redwoodjs#5482)
  chore(deps): update dependency firebase to v9.8.1 (redwoodjs#5485)
  fix(deps): update dependency @types/aws-lambda to v8.10.97 (redwoodjs#5486)
  chore(deps): update dependency @nhost/nhost-js to v1.1.10 (redwoodjs#5479)
  chore(deps): update dependency @nhost/hasura-auth-js to v1.1.5 (redwoodjs#5478)
  Fixing type for BrowserOnly children (redwoodjs#5475)
  fix: Run dedupe during upgrade on yarn 3 (redwoodjs#5458)
  Fix/ts resolvers type (redwoodjs#5437)
@netlify
Copy link

netlify bot commented May 10, 2022

Deploy Preview for redwoodjs-docs ready!

Name Link
🔨 Latest commit 049ee24
🔍 Latest deploy log https://app.netlify.com/sites/redwoodjs-docs/deploys/62debf2d21e1080008eb4abe
😎 Deploy Preview https://deploy-preview-5491--redwoodjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@jtoar jtoar mentioned this pull request May 11, 2022
@dac09
Copy link
Contributor Author

dac09 commented May 11, 2022

@jtoar jtoar linked an issue May 11, 2022 that may be closed by this pull request
@dac09 dac09 added the release:feature This PR introduces a new feature label May 16, 2022
@dac09 dac09 changed the title TypeScript strict mode docs + Codegen changes TypeScript strict mode support + docs May 17, 2022
dac09 added 10 commits May 17, 2022 17:06
…ctmode-gen

* 'main' of github.com:redwoodjs/redwood: (91 commits)
  Add example usage of useRegister and useErrorStyles (redwoodjs#5692)
  chore(deps): update dependency @envelop/testing to v4.3.3 (redwoodjs#5690)
  Update contributing docs (redwoodjs#5685)
  Fix typos in docs (redwoodjs#5694)
  Fix typo in ArticleCell code snippet of Tutorial 2 docs (redwoodjs#5695)
  fix(deps): update dependency core-js to v3.22.8 (redwoodjs#5683)
  fix(deps): update dependency webpack-dev-server to v4.9.1 (redwoodjs#5684)
  Fix typo (redwoodjs#5686)
  Add warning box for missing roles in authorization doc (redwoodjs#5611)
  Fix dbAuth on AWS Lambda (redwoodjs#5474)
  fix(deps): update dependency @types/jest to v27.5.2 (redwoodjs#5681)
  fix(deps): update dependency vscode-languageserver-textdocument to v1.0.5 (redwoodjs#5679)
  chore(deps): update dependency @nhost/hasura-auth-js to v1.1.12 (redwoodjs#5677)
  fix(deps): update dependency systeminformation to v5.11.16 (redwoodjs#5676)
  fix(deps): update dependency @types/node to v16.11.38 (redwoodjs#5674)
  fix(deps): update dependency @apollo/client to v3.6.6 (redwoodjs#5671)
  chore(deps): update dependency @nhost/hasura-auth-js to v1.1.11 (redwoodjs#5669)
  fix(deps): update dependency react-hook-form to v7.31.3 (redwoodjs#5666)
  chore(deps): update dependency firebase to v9.8.2 (redwoodjs#5665)
  docs: Details for TS generics when mocking queries (redwoodjs#5645)
  ...
@dac09 dac09 requested review from jtoar and cannikin July 22, 2022 17:21
@dac09 dac09 enabled auto-merge (squash) July 24, 2022 14:46
@dac09 dac09 dismissed cannikin’s stale review July 25, 2022 16:30

Addressed comments

@dac09 dac09 merged commit 3608794 into redwoodjs:main Jul 25, 2022
@redwoodjs-bot redwoodjs-bot bot added this to the next-release milestone Jul 25, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 8, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 8, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 9, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 9, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 10, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 10, 2022
Philzen added a commit to Philzen/redwood that referenced this pull request Aug 10, 2022
@jtoar jtoar modified the milestones: next-release, v3.0.0 Sep 2, 2022
Tobbe added a commit that referenced this pull request Apr 27, 2023
…6061)

* Exclude unused variable `userAttributes` from ESLint checks

* Add all dependencies to dependency array of effect hook which validates the token

* Fix typescript strict mode warning (implicit type any) on reset password page

Adds to / completes #5491

* Update test fixture

* Ensure all eslint `no-used-vars` ignores are compatible with JS

Adds to / completes 3fe7dca

* Update test snapshots

* Update test fixture

---------

Co-authored-by: Tobbe Lundberg <[email protected]>
Co-authored-by: David Price <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
Status: Archived
5 participants