Skip to content

Commit b1932b0

Browse files
authored
Refactor error codes in the TS plugin (vercel#42585)
Small code refactoring. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent 3e2e39c commit b1932b0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/next/server/next-typescript.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ const DISALLOWED_SERVER_REACT_APIS: string[] = [
2929

3030
const ALLOWED_EXPORTS = ['config', 'generateStaticParams']
3131

32+
const NEXT_TS_ERRORS = {
33+
INVALID_SERVER_API: 71001,
34+
INVALID_ENTRY_EXPORT: 71002,
35+
INVALID_OPTION_VALUE: 71003,
36+
MISPLACED_CLIENT_ENTRY: 71004,
37+
}
38+
3239
const API_DOCS: Record<
3340
string,
3441
{
@@ -496,7 +503,7 @@ export function createTSPlugin(modules: {
496503
prior.push({
497504
file: source,
498505
category: ts.DiagnosticCategory.Error,
499-
code: 71004,
506+
code: NEXT_TS_ERRORS.MISPLACED_CLIENT_ENTRY,
500507
...e,
501508
})
502509
isClientEntry = false
@@ -519,7 +526,7 @@ export function createTSPlugin(modules: {
519526
prior.push({
520527
file: source,
521528
category: ts.DiagnosticCategory.Error,
522-
code: 71001,
529+
code: NEXT_TS_ERRORS.INVALID_SERVER_API,
523530
messageText: `"${name}" is not allowed in Server Components.`,
524531
start: element.name.getStart(),
525532
length:
@@ -546,7 +553,7 @@ export function createTSPlugin(modules: {
546553
prior.push({
547554
file: source,
548555
category: ts.DiagnosticCategory.Error,
549-
code: 71002,
556+
code: NEXT_TS_ERRORS.INVALID_ENTRY_EXPORT,
550557
messageText: `"${name.text}" is not a valid Next.js entry export value.`,
551558
start: name.getStart(),
552559
length: name.getEnd() - name.getStart(),
@@ -620,7 +627,7 @@ export function createTSPlugin(modules: {
620627
prior.push({
621628
file: source,
622629
category: ts.DiagnosticCategory.Error,
623-
code: 71003,
630+
code: NEXT_TS_ERRORS.INVALID_OPTION_VALUE,
624631
messageText:
625632
errorMessage ||
626633
`"${displayedValue}" is not a valid value for the "${name.text}" option.`,

0 commit comments

Comments
 (0)