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

refactor(start): export the MiddlewareAfterServer type #2891

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

arfath-linklet
Copy link
Contributor

In a monorepo setup where middlewares and serverFn are declared in different packages. Some types have issues with inference.

Example:

export const authenticated = createMiddleware().server(async ({ next }) => {
  const session = await getSession();

  if (!session) {
    throw redirect({
      to: "/sign-in/$",
    });
  }

  return await next({
    context: {
      session,
    },
  });
});

Reports:

The inferred type of 'authenticated' cannot be named without a reference to '../../../../node_modules/@tanstack/start/dist/esm/client/createMiddleware'. This is likely not portable. A type annotation is necessary.ts(2742)

Workaround:

// TODO: temporary fixes inferred types
export { type MiddlewareAfterServer } from "../../../../node_modules/@tanstack/start/dist/esm/client/createMiddleware";

export const authenticated = createMiddleware().server(async ({ next }) => {
...

exporting MiddlewareAfterServer resolves this. This may have been a missed export.

@Talent30
Copy link

Talent30 commented Nov 30, 2024

Hi @SeanCassiere. Could you review this PR when you are free please? This is a small yet important for DX.

Copy link

nx-cloud bot commented Nov 30, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d2f177e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

Copy link

pkg-pr-new bot commented Nov 30, 2024

Open in Stackblitz

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@2891

@tanstack/create-router

npm i https://pkg.pr.new/@tanstack/create-router@2891

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@2891

@tanstack/react-cross-context

npm i https://pkg.pr.new/@tanstack/react-cross-context@2891

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@2891

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@2891

@tanstack/react-router-with-query

npm i https://pkg.pr.new/@tanstack/react-router-with-query@2891

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@2891

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@2891

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@2891

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@2891

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@2891

@tanstack/start

npm i https://pkg.pr.new/@tanstack/start@2891

@tanstack/start-vite-plugin

npm i https://pkg.pr.new/@tanstack/start-vite-plugin@2891

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@2891

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@2891

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@2891

commit: d2f177e

@SeanCassiere SeanCassiere changed the title fix(start): Exports MiddlewareAfterServer type refactor(start): export the MiddlewareAfterServer type Dec 2, 2024
@SeanCassiere SeanCassiere merged commit 8af5150 into TanStack:main Dec 2, 2024
5 checks passed
timoconnellaus pushed a commit to timoconnellaus/tanstack-router that referenced this pull request Dec 4, 2024
timoconnellaus pushed a commit to timoconnellaus/tanstack-router that referenced this pull request Dec 19, 2024
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.

3 participants