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

Improve type checking error message for invalid props #43903

Merged
merged 2 commits into from Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions packages/next/lib/typescript/diagnosticFormatter.ts
Expand Up @@ -62,10 +62,11 @@ function getFormattedLayoutAndPageDiagnosticMessageText(
if (types) {
main += '\n' + ' '.repeat(indent * 2)

if (types[2] === 'PageComponent') {
main += `The exported page component isn't correctly typed.`
} else if (types[2] === 'LayoutComponent') {
main += `The exported layout component isn't correctly typed.`
if (
types[2] === 'PageComponent' ||
types[2] === 'LayoutComponent'
) {
main += `The exported ${type} component isn't correctly typed.`
} else {
main += `Expected "${chalk.bold(
types[2].replace(
Expand All @@ -80,6 +81,20 @@ function getFormattedLayoutAndPageDiagnosticMessageText(
main += '\n' + ' '.repeat(indent * 2)
main += `Invalid configuration:`
break
case 2739:
const invalidProp = item.messageText.match(
/Type '(.+)' is missing the following properties from type '(.+)'/
)
if (invalidProp) {
if (
invalidProp[1] === 'LayoutProps' ||
invalidProp[1] === 'PageProps'
) {
main += '\n' + ' '.repeat(indent * 2)
main += `Prop "${invalidProp[2]}" is incompatible with the ${type}.`
}
}
break
case 2559:
const invalid = item.messageText.match(/Type '(.+)' has/)
if (invalid) {
Expand Down