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

Single fetch: returning submission.reply() with action results in type never. #9374

Closed
coji opened this issue May 4, 2024 · 3 comments
Closed

Comments

@coji
Copy link

coji commented May 4, 2024

I have introduced single fetch and added the settings to tsconfig.json,
I added a setting to tsconfig.json, but when the return value of the conform submission.reply() used in the form validation was included
The type returned by useActionData is never.

tsconfig.json is as follows, with types added to the content created by create remix.

{
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "**/.server/**/*.ts",
    "**/.server/**/*.tsx",
    "**/.client/**/*.ts",
    "**/.client/**/*.tsx"
  ],
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "types": [
      "@remix-run/node",
      "vite/client",
      "@remix-run/react/future/single-fetch.d.ts"
    ],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "target": "ES2022",
    "strict": true,
    "allowJs": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./app/*"]
    },

    // Vite takes care of building everything, not tsc.
    "noEmit": true
  }
}

Reproduction

https://stackblitz.com/~/github.com/coji/conform-on-remix-single-fetch

image

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M2
    Memory: 2.76 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    @remix-run/dev: ^2.9.1 => 2.9.1 
    @remix-run/node: ^2.9.1 => 2.9.1 
    @remix-run/react: ^2.9.1 => 2.9.1 
    @remix-run/serve: ^2.9.1 => 2.9.1 
    vite: ^5.2.11 => 5.2.11

Used Package Manager

pnpm

Expected Behavior

The return type of useActionData is as follows.

{
    lastRusult: SubmissionResult<string[]>;
> | undefined
}

Actual Behavior

The type is never.

const actionData: never

Therefore, the following error is displayed in typecheck.

$ pnpm typecheck

> conform-on-remix-single-fetch@ typecheck /Users/coji/progs/spike/conform/conform-on-remix-single-fetch
> tsc

app/routes/_index.tsx:19:29 - error TS2339: Property 'lastResult' does not exist on type 'never'.

19     lastResult: actionData?.lastResult,
                               ~~~~~~~~~~


Found 1 error in app/routes/_index.tsx:19
@coji coji changed the title single fetch: returning conform.reply() with action results in type never. Single fetch: returning conform.reply() with action results in type never. May 4, 2024
@coji coji changed the title Single fetch: returning conform.reply() with action results in type never. Single fetch: returning submission.reply() with action results in type never. May 4, 2024
@tobiasfoerg
Copy link

I ran into the same issue. This is because SubmissionResult has a prop with Result<string, unknown>.

@brophdawg11
Copy link
Contributor

Yeah I agree. The types for single fetch are restricting loaders/actions to returning types we know can be serialized by turbo-stream and won't throw an error at runtime. The unknown is problematic since we can't know what it will be and can't be sure it's something turbo-stream knows how to serialize.

@coji
Copy link
Author

coji commented May 12, 2024

@brophdawg11

Bumping to remix v2.9.2 eliminated the error.
Thank you very much!

https://stackblitz.com/~/github.com/coji/conform-on-remix-single-fetch/pull/2?file=app/routes/_index.tsx

@coji coji closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants