Repository navigation
Conversation
New TypeScript apps set `"strict": true` in web, api and scripts tsconfig.json, and the code generators and setup commands write is typed for strict mode: scaffolds, cells, services and their tests, dbAuth (incl. WebAuthn), realtime, uploads, cache, sentry, tenancy, og-image and the third-party auth providers' api/src/lib/auth.ts. Generated types the generated code relies on are more precise: QueryResolvers/MutationResolvers fields are required, api-side JSON inputs use Prisma's input JSON types, CurrentUser excludes null, and <Set wrap> infers its forwarded props from the wrapper components. Existing apps keep their tsconfig files. Docs and the v8 release notes describe how to turn strict mode on.
✅ Deploy Preview for cedarjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The supplied review evidence identifies no confirmed behavior issue that requires holding the merge. Pre-merge checks |
|
|
View your CI Pipeline Execution ↗ for commit 1cb1dd8
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
|
- Regenerate the JS create-cedar-app template and inline the roles type in the TS auth template - Spread story args before the fixed id in the test-project page stories - Generate non-nullable items for Prisma scalar and enum lists in SDLs - Keep findUnique for optional to-one relation resolvers
…to tobbe-ts-strict-default # Conflicts: # .changesets/release_notes_v8.md
|
@coderabbitai review |
✅ Action performedReview finished.
|
# Conflicts: # .changesets/release_notes_v8.md # docs/docs/typescript/generated-types.md # packages/internal/src/__tests__/typeDefinitions.test.ts # packages/internal/src/generate/templates/web-test-globals.d.ts.template # packages/router/src/Set.tsx
Summary
New TypeScript apps created with
create-cedar-apphave TypeScript'sstrictmode turned on, and the code thatyarn cedar generate ...andyarn cedar setup ...write type-checks under strict mode. This is one of the planned Cedar v8 items.Existing apps aren't changed: their tsconfig files keep their settings, and there's no upgrade script. The docs and the v8 release notes explain how to turn strict mode on in an existing app. Code generated into an app without strict mode works as before.
Related PRs
This PR was split up to stay under CodeRabbit's 100-file limit. The other parts are merged:
@cedarjs/internalcodegen,LoggedInUser/CurrentUserin@cedarjs/auth,@cedarjs/uploads,MemcachedClient)yarn cedar setup ...output (auth providers, cache, sentry, realtime, uploads, tenancy)<Set>wrappers only getchildren, and the scaffold generates a per-model layout likePostsScaffoldLayout. That's what makes the scaffold's routes strict-clean.Still to come: #2997 (draft), the hand-updated
test-project-live/-pnpmfixture copies. Merge it after this PR.What changed
Templates (
create-cedar-app)"strict": trueinweb/tsconfig.json,api/tsconfig.jsonandscripts/tsconfig.json. None of the existing options overlapped withstrict(nostrict*/noImplicitAnyflags), so nothing else needed tidying.api/src/lib/auth.ts:hasRoleandrequireAuthget a typedrolesargument.ts-to-js, so itsjsconfig.jsonfiles also setstrict. That only takes effect if an app turns oncheckJs.create-cedar-rsc-apphas no templates of its own; it downloads__fixtures__/test-project-rsc-kitchen-sinkfrom GitHub. That fixture is left as is.create-cedar-app's tests only list template files, so no snapshot changes.Generators (
yarn cedar generate)--crud, also via sdl/scaffold):update<Model>turnsnullintoundefinedfor fields that are required in Prisma (GraphQL can't express "optional, but not null"). NullableJsonfields mapnulltoPrisma.DbNullon create and update, since Prisma rejectsnullforJsonfields.findUniqueOrThrow({ where: { id: root.id } })for required and list relations, so they aren't nullable. Optional to-one relations keepfindUnique, so they returnnullwhen the parent is gone (for example when selected fromdelete<Model>).createdAt/updatedAt(not in the SDL inputs; this was a type error even without strict mode). String@idfields without a default get unique scenario values.onSavetakes aCreate<Model>Input, anderroris optional.<model>.<idName>itself and uses theUpdate<Model>Mutationtype. This also fixes the hard-codedidvariable for custom id names.?? undefined, and the empty enum radio option is mapped with!value.truncateandcheckboxInputTagformatters accept nullish values.--webauthn: typed login page (useRef<HTMLInputElement>, form data,catchnarrowing, null-safewebAuthnclient).src/subscriptions/<name>/<name>.js, the file the generator writes.tags: [String!]!), so generated create/update inputs match Prisma's input types.outputprops.tsconfig.jsonsetsstrict.Test-project fixture
tasks/test-project:__cedarjs_db_imported__global.nullcurrentUser.createContactstaysContact!,full-nameis read null-safely, and the describe-scenario test is null-safe.__fixtures__/test-projectis the output ofyarn rebuild-test-project-fixture.__fixtures__/test-project-liveand-pnpmget the same changes in chore(fixtures): sync test-project-live and -pnpm with strict test-project #2997.Docs and release notes
docs/docs/typescript/strict-mode.md:getCurrentUsersections describe what the generators produce now.docs/docs/typescript/introduction.mdsays new projects have strict mode on..changesets/release_notes_v8.md. The generated-type changes are described in feat(types)!: more precise generated and exported types for strict apps #2995's "More precise generated types" section.Verification
yarn build, thenyarn rebuild-test-project-fixture(success message, no failure text).yarn build:test-project <tmp> --linkfrom the rebuilt fixture, then in that project:yarn cedar type-check(strict): 0 errorsyarn cedar lint: passesyarn cedar test api: 24 tests passyarn cedar test web: 45 tests passcreate-cedar-apppluscfw project:tarsync, then 43 generator/setup commands, all of which succeeded:Widgetmodel with every scalar type, nullable variants,Json/Json?, enums,BigInt,Decimaland@updatedAt; required and optional relations; and aString @idmodel--list,--query)sdl --crud,service --crud --testssetup jobsand job, data-migrationsetup auth dbAuth --webauthn --createUserModelandg dbAuth --webauthnrealtime --includeExampleswith a subscription and a live query, uploads (fs, db, s3), cache (redis), graphql fragments and trusted-documents, sentry, og-imageyarn cedar type-check(strict): 1 error, pre-existing (see known gaps)yarn cedar test api: 40 tests passyarn cedar test web: 34 tests passsetup authauth0, supabase, clerk and firebase, each on a clean copy:yarn cedar type-check0 errors.Usermodel, plussetup tenancyandsetup i18n: no strict-specific errors remain.yarn vitest runinpackages/cli: 1717 tests pass. The snapshots were updated withvitest -uand each diff was reviewed.packages/create-cedar-app: 6 tests passpackages/internal: 308 tests passpackages/router: 244 tests pass, plustest:types(21)packages/uploads: 124 tests passpackages/auth-providers/dbAuth/weband the auth provider setup packages pass, and so do thepackages/apicache testsKnown gaps
These all fail without strict mode too; strict mode doesn't change them:
api/src/directives/requireAuth/requireAuth.test.tsmockscurrentUser: { id: 1 }. That doesn't match apps whosegetCurrentUserreturns a string id (setup auth dbAuth --createUserModel) or always returnsroles(netlify).setup i18nwritesweb/.storybook/preview.tsx, which needs Storybook (@storybook/csf) installed to type-check.fullName, which the--createUserModelUsermodel doesn't have.setup supertokensweb output (PreBuiltUIinRoutes.tsx) wasn't type-checked on a clean app.autoFocus) leave import-order or prettier lint errors thatyarn cedar lint --fixfixes.setup authwas verified for auth0, supabase, clerk and firebase on clean apps. netlify, azureActiveDirectory, supertokens and custom were only run on top of each other in one app, so those results aren't conclusive.