Skip to content

fix(ts-plugin): allow promise-like server action returns#94292

Open
cupkk wants to merge 1 commit into
vercel:canaryfrom
cupkk:codex/fix-server-action-promise-like
Open

fix(ts-plugin): allow promise-like server action returns#94292
cupkk wants to merge 1 commit into
vercel:canaryfrom
cupkk:codex/fix-server-action-promise-like

Conversation

@cupkk
Copy link
Copy Markdown

@cupkk cupkk commented Jun 1, 2026

Fixes #74722.

Summary

  • Treat PromiseLike<T> return types as valid for "use server" exports.
  • Accept intersection return types that include a promise-like constituent, such as Promise<T> & { __errorType?: Error }.
  • Add focused unit coverage for PromiseLike, promise intersections, and non-promise returns.

Why

The TypeScript plugin only recognized return types whose type reference target printed as Promise<T>. That rejected valid promise-like server action return types, including the shape reported in the issue.

Validation

  • packages/next/src/server/typescript/rules/server-boundary.test.ts with an isolated Jest runner: 2 tests passed.
  • TypeScript compile checks for the touched rule/test against TypeScript 5.1.6 and 6.0.2.
  • npx -y prettier@3.6.2 --check packages/next/src/server/typescript/rules/server-boundary.ts packages/next/src/server/typescript/rules/server-boundary.test.ts
  • git diff --check

@cupkk cupkk marked this pull request as ready for review June 1, 2026 06:21
Copilot AI review requested due to automatic review settings June 1, 2026 06:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the server-boundary TypeScript rule to treat promise-like return types (including intersections) as valid, and adds tests to cover the new behavior.

Changes:

  • Expand return-type detection from Promise<T> to also accept PromiseLike<T> and intersections containing promise-like types.
  • Add a new Jest test suite validating allowed promise-like/intersection types and rejecting non-promise returns.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/next/src/server/typescript/rules/server-boundary.ts Updates the promise-return detection logic to include PromiseLike and intersection types.
packages/next/src/server/typescript/rules/server-boundary.test.ts Adds tests that exercise the new promise-like/intersection behavior and a basic negative case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +21
// Check if the type is promise-like.
function isPromiseLikeType(
type: tsModule.Type,
typeChecker: tsModule.TypeChecker
): boolean {
if (type.isIntersection()) {
return type.types.some((t) => isPromiseLikeType(t, typeChecker))
}

const typeReferenceType = type as tsModule.TypeReference
if (!typeReferenceType.target) return false

// target should be Promise or Promise<...>
if (
!/^Promise(<.+>)?$/.test(typeChecker.typeToString(typeReferenceType.target))
) {
return false
}

return true
return /^Promise(?:Like)?(<.+>)?$/.test(
typeChecker.typeToString(typeReferenceType.target)
)
import serverBoundary from './server-boundary'

function getDiagnostics(sourceText: string) {
const fileName = 'C:/project/app/actions.ts'
getProgram: () => program,
},
project: {
getCurrentDirectory: () => 'C:/project',
Comment on lines +28 to +43
init({
ts,
info: {
languageService: {
getProgram: () => program,
},
project: {
getCurrentDirectory: () => 'C:/project',
projectService: {
logger: {
info: jest.fn(),
},
},
},
} as any,
})
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.

TypeScript Plugin Incorrectly Error PromiseLike Return Types in "use server" file

2 participants