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

[Bug]: createCell doesn't typecheck with strict mode #6460

Open
1 task done
jmackie opened this issue Sep 27, 2022 · 3 comments
Open
1 task done

[Bug]: createCell doesn't typecheck with strict mode #6460

jmackie opened this issue Sep 27, 2022 · 3 comments
Assignees
Labels
bug/needs-info More information is needed for reproduction

Comments

@jmackie
Copy link
Contributor

jmackie commented Sep 27, 2022

What's not working?

Related to #5491

I don't think the typing of createCell is quite right...

Attempting to use createCell "by hand" in a TypeScript file (as we do in a few places at @project-nous) with strict type-checking enabled throws an error in v3.

How do we reproduce the bug?

  1. Generate a new redwood (v3) project with
yarn create redwood-app ./redwoodblog
  1. Generate a new cell
yarn redwood generate cell Example
  1. Mock out the GraphQL schema types
diff --git a/web/src/components/ExampleCell/ExampleCell.tsx b/web/src/components/ExampleCell/ExampleCell.tsx
index 4125e09..618f625 100644
--- a/web/src/components/ExampleCell/ExampleCell.tsx
+++ b/web/src/components/ExampleCell/ExampleCell.tsx
@@ -1,6 +1,9 @@
-import type { FindExampleQuery, FindExampleQueryVariables } from 'types/graphql'
+//import type { FindExampleQuery, FindExampleQueryVariables } from 'types/graphql'
 import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web'
 
+type FindExampleQuery = { example: { id: number } }
+type FindExampleQueryVariables = {}
+
 export const QUERY = gql`
   query FindExampleQuery($id: Int!) {
     example: example(id: $id) {
  1. Add createCell stuff as per babel-plugin-redwood-cell
diff --git a/web/src/components/ExampleCell/ExampleCell.tsx b/web/src/components/ExampleCell/ExampleCell.tsx
index 618f625..165d753 100644
--- a/web/src/components/ExampleCell/ExampleCell.tsx
+++ b/web/src/components/ExampleCell/ExampleCell.tsx
@@ -1,5 +1,5 @@
 //import type { FindExampleQuery, FindExampleQueryVariables } from 'types/graphql'
-import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web'
+import { CellSuccessProps, CellFailureProps, createCell } from '@redwoodjs/web'
 
 type FindExampleQuery = { example: { id: string } }
 type FindExampleQueryVariables = {}
@@ -27,3 +27,5 @@ export const Success = ({
 }: CellSuccessProps<FindExampleQuery, FindExampleQueryVariables>) => {
   return <div>{JSON.stringify(example)}</div>
 }
+export default createCell({ QUERY, Loading, Success, Failure, Empty })
  1. Turn on strict type checking
diff --git a/web/tsconfig.json b/web/tsconfig.json
index fb9c789..1ccf381 100644
--- a/web/tsconfig.json
+++ b/web/tsconfig.json
@@ -1,5 +1,6 @@
 {
   "compilerOptions": {
+    "strict": true,
     "noEmit": true,
     "allowJs": true,
     "esModuleInterop": true,
  1. Type check
yarn redwood type-check
  1. See some grizzly type errors

What's your environment? (If it applies)

No response

Are you interested in working on this?

  • I'm interested in working on this
@jmackie jmackie added the bug/needs-info More information is needed for reproduction label Sep 27, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Sep 27, 2022
@redwoodjs-bot redwoodjs-bot bot moved this to Triage in Main Sep 27, 2022
@Tobbe Tobbe assigned Tobbe and unassigned simoncrypta Oct 3, 2022
@Tobbe
Copy link
Member

Tobbe commented Oct 4, 2022

This is the error I'm getting. Same one you're seeing?

image

@Tobbe
Copy link
Member

Tobbe commented Oct 4, 2022

If I first make sure the Example model exists and sdl is generated I get this error

image

Same error as shown by yarn rw type-check

image

@Tobbe
Copy link
Member

Tobbe commented Oct 4, 2022

If I change the Success component declaration to look like this it works

export const Success = ({ example }: Partial<FindExampleQuery>) => {

Not exactly sure why yet, but it's a workaround for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction
Projects
Status: Triage
Development

No branches or pull requests

3 participants