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

Can fix this error Type error: 34 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>() #71

Open
lakshmiganesh0925 opened this issue Feb 12, 2025 · 1 comment

Comments

@lakshmiganesh0925
Copy link

.next/types/app/patients/[userId]/new-appointment/page.ts:34:29 Type error: Type 'SearchParamProps' does not satisfy the constraint 'PageProps'. Types of property 'params' are incompatible. Type '{ userId: string; } | Promise<{ userId: string; }>' is not assignable to type 'Promise | undefined'. Type '{ userId: string; }' is missing the following properties from type 'Promise': then, catch, finally, [Symbol.toStringTag] 32 | 33 | // Check the prop type of the entry function > 34 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>() | ^ 35 | 36 | // Check the arguments and return type of the generateMetadata function 37 | if ('generateMetadata' in entry) { Static worker exited with code: 1 and signal: null

// File: C:\Users\Ganesh\Desktop\HealthCheckup\nxtcheckup\app\patients[userId]\new-appointment\page.tsx
import * as entry from '../../../../../../app/patients/[userId]/new-appointment/page.js'
import type { ResolvingMetadata, ResolvingViewport } from 'next/dist/lib/metadata/types/metadata-interface.js'

type TEntry = typeof import('../../../../../../app/patients/[userId]/new-appointment/page.js')

type SegmentParams = T extends Record<string, any>
? { [K in keyof T]: T[K] extends string ? string | string[] | undefined : never }
: T

// Check that the entry is a valid entry
checkFields<Diff<{
default: Function
config?: {}
generateStaticParams?: Function
revalidate?: RevalidateRange | false
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
dynamicParams?: boolean
fetchCache?: 'auto' | 'force-no-store' | 'only-no-store' | 'default-no-store' | 'default-cache' | 'only-cache' | 'force-cache'
preferredRegion?: 'auto' | 'global' | 'home' | string | string[]
runtime?: 'nodejs' | 'experimental-edge' | 'edge'
maxDuration?: number

metadata?: any
generateMetadata?: Function
viewport?: any
generateViewport?: Function
experimental_ppr?: boolean

}, TEntry, ''>>()

// Check the prop type of the entry function
checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()

// Check the arguments and return type of the generateMetadata function
if ('generateMetadata' in entry) {
checkFields<Diff<PageProps, FirstArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
checkFields<Diff<ResolvingMetadata, SecondArg<MaybeField<TEntry, 'generateMetadata'>>, 'generateMetadata'>>()
}

// Check the arguments and return type of the generateViewport function
if ('generateViewport' in entry) {
checkFields<Diff<PageProps, FirstArg<MaybeField<TEntry, 'generateViewport'>>, 'generateViewport'>>()
checkFields<Diff<ResolvingViewport, SecondArg<MaybeField<TEntry, 'generateViewport'>>, 'generateViewport'>>()
}

// Check the arguments and return type of the generateStaticParams function
if ('generateStaticParams' in entry) {
checkFields<Diff<{ params: SegmentParams }, FirstArg<MaybeField<TEntry, 'generateStaticParams'>>, 'generateStaticParams'>>()
checkFields<Diff<{ tag: 'generateStaticParams', return_type: any[] | Promise<any[]> }, { tag: 'generateStaticParams', return_type: ReturnType<MaybeField<TEntry, 'generateStaticParams'>> }>>()
}

export interface PageProps {
params?: Promise
searchParams?: Promise
}
export interface LayoutProps {
children?: React.ReactNode

params?: Promise
}

// =============
// Utility types
type RevalidateRange = T extends { revalidate: any } ? NonNegative<T['revalidate']> : never

// If T is unknown or any, it will be an empty {} type. Otherwise, it will be the same as Omit<T, keyof Base>.
type OmitWithTag<T, K extends keyof any, _M> = Omit<T, K>
type Diff<Base, T extends Base, Message extends string = ''> = 0 extends (1 & T) ? {} : OmitWithTag<T, keyof Base, Message>

type FirstArg = T extends (...args: [infer T, any]) => any ? unknown extends T ? any : T : never
type SecondArg = T extends (...args: [any, infer T]) => any ? unknown extends T ? any : T : never
type MaybeField<T, K extends string> = T extends { [k in K]: infer G } ? G extends Function ? G : never : never

function checkFields<_ extends { [k in keyof any]: never }>() {}

// https://github.com/sindresorhus/type-fest
type Numeric = number | bigint
type Zero = 0 | 0n
type Negative = T extends Zero ? never : ${T} extends -${string} ? T : never
type NonNegative = T extends Zero ? T : Negative extends never ? T : 'invalid_negative_number'
Type 'SearchParamProps' does not satisfy the constraint 'PageProps'.
Types of property 'params' are incompatible.
Type '{ userId: string; } | Promise<{ userId: string; }>' is not assignable to type 'Promise | undefined'.
Type '{ userId: string; }' is missing the following properties from type 'Promise': then, catch, finally, [Symbol.toStringTag]

@Davidon4
Copy link

Change the name of the file from page. It is an issue with next router. You can call it new-appointment.tsx

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

No branches or pull requests

2 participants