fix(ts-plugin): allow promise-like server action returns#94292
Open
cupkk wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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 acceptPromiseLike<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, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #74722.
Summary
PromiseLike<T>return types as valid for"use server"exports.Promise<T> & { __errorType?: Error }.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.tswith an isolated Jest runner: 2 tests passed.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.tsgit diff --check