-
Notifications
You must be signed in to change notification settings - Fork 110
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
chore: add typecheck and fix type #633
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,13 @@ | |
}, | ||
"scripts": { | ||
"build:js": "rollup -c", | ||
"build:ts": "tsc", | ||
"build:ts": "tsc --emitDeclarationOnly", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when running |
||
"build": "pnpm run \"/^build:.*/\"", | ||
"dev:js": "pnpm run build:js --watch", | ||
"dev:ts": "pnpm run build:ts --watch", | ||
"dev": "pnpm run \"/^dev:.*/\"", | ||
"prepare": "pnpm run build" | ||
"prepare": "pnpm run build", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export type SubmissionState = { | |
validated: Record<string, boolean>; | ||
}; | ||
|
||
export type SubmissionContext<Value = null, FormError = string[]> = { | ||
export type SubmissionContext<Value = unknown, FormError = string[]> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
intent: Intent | null; | ||
payload: Record<string, unknown>; | ||
fields: Set<string>; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,18 +10,14 @@ import { | |
type SubscriptionScope, | ||
type SubscriptionSubject, | ||
type FormOptions as BaseFormOptions, | ||
unstable_createFormContext as createBaseFormContext, | ||
unstable_createFormContext, | ||
formatPaths, | ||
getPaths, | ||
isPrefix, | ||
STATE, | ||
INTENT, | ||
} from '@conform-to/dom'; | ||
import { | ||
type FormEvent, | ||
type ReactElement, | ||
type ReactNode, | ||
type MutableRefObject, | ||
createContext, | ||
useMemo, | ||
useCallback, | ||
|
@@ -32,15 +28,7 @@ import { | |
|
||
export type Pretty<T> = { [K in keyof T]: T[K] } & {}; | ||
|
||
export type Primitive = | ||
| string | ||
| number | ||
| bigint | ||
| boolean | ||
| Date | ||
| File | ||
| null | ||
| undefined; | ||
export type Primitive = string | number | bigint | boolean | null | undefined; | ||
|
||
export type Metadata< | ||
Schema, | ||
|
@@ -83,7 +71,7 @@ type SubfieldMetadata< | |
Schema, | ||
FormSchema extends Record<string, any>, | ||
FormError, | ||
> = [Schema] extends [Primitive] | ||
> = [Schema] extends [Primitive | Date | File] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edmundhung this seems to be the only place Primitive is being used, whats the intent for overloading the term "Primitive" here with maybe another term like |
||
? {} | ||
: [Schema] extends [Array<infer Item> | null | undefined] | ||
? { | ||
|
@@ -144,7 +132,7 @@ export function useFormContext<Schema extends Record<string, any>, FormError>( | |
|
||
export function useFormState<FormError>( | ||
form: FormContext<any, FormError>, | ||
subjectRef?: MutableRefObject<SubscriptionSubject>, | ||
subjectRef?: React.MutableRefObject<SubscriptionSubject>, | ||
): FormState<FormError> { | ||
const subscribe = useCallback( | ||
(callback: () => void) => | ||
|
@@ -157,8 +145,8 @@ export function useFormState<FormError>( | |
|
||
export function FormProvider(props: { | ||
context: Wrapped<FormContext<any, any>>; | ||
children: ReactNode; | ||
}): ReactElement { | ||
children: React.ReactNode; | ||
}): React.ReactElement { | ||
const forms = useContext(Form); | ||
const context = getWrappedFormContext(props.context); | ||
const value = useMemo( | ||
|
@@ -184,7 +172,7 @@ export function FormStateInput(props: { formId?: string }): React.ReactElement { | |
|
||
export function useSubjectRef( | ||
initialSubject: SubscriptionSubject = {}, | ||
): MutableRefObject<SubscriptionSubject> { | ||
): React.MutableRefObject<SubscriptionSubject> { | ||
const subjectRef = useRef(initialSubject); | ||
|
||
// Reset the subject everytime the component is rerendered | ||
|
@@ -195,17 +183,17 @@ export function useSubjectRef( | |
} | ||
|
||
export function updateSubjectRef( | ||
ref: MutableRefObject<SubscriptionSubject>, | ||
ref: React.MutableRefObject<SubscriptionSubject>, | ||
subject: 'status' | 'formId', | ||
): void; | ||
export function updateSubjectRef( | ||
ref: MutableRefObject<SubscriptionSubject>, | ||
ref: React.MutableRefObject<SubscriptionSubject>, | ||
subject: Exclude<keyof SubscriptionSubject, 'status' | 'formId'>, | ||
scope: keyof SubscriptionScope, | ||
name: string, | ||
): void; | ||
export function updateSubjectRef( | ||
ref: MutableRefObject<SubscriptionSubject>, | ||
ref: React.MutableRefObject<SubscriptionSubject>, | ||
subject: keyof SubscriptionSubject, | ||
scope?: keyof SubscriptionScope, | ||
name?: string, | ||
|
@@ -226,7 +214,7 @@ export function getMetadata< | |
FormSchema extends Record<string, any>, | ||
>( | ||
context: FormContext<FormSchema, FormError, any>, | ||
subjectRef: MutableRefObject<SubscriptionSubject>, | ||
subjectRef: React.MutableRefObject<SubscriptionSubject>, | ||
stateSnapshot: FormState<FormError>, | ||
name: FieldName<Schema, FormSchema, FormError> = '', | ||
): Metadata<Schema, FormSchema, FormError> { | ||
|
@@ -272,24 +260,6 @@ export function getMetadata< | |
|
||
return result; | ||
}, | ||
get getFieldset() { | ||
return () => | ||
new Proxy({} as any, { | ||
get(target, key, receiver) { | ||
if (typeof key === 'string') { | ||
return getFieldMetadata( | ||
context, | ||
subjectRef, | ||
stateSnapshot, | ||
name, | ||
key, | ||
); | ||
} | ||
|
||
return Reflect.get(target, key, receiver); | ||
}, | ||
}); | ||
}, | ||
Comment on lines
-275
to
-292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edmundhung based off the type it says |
||
}, | ||
{ | ||
get(target, key, receiver) { | ||
|
@@ -334,7 +304,7 @@ export function getFieldMetadata< | |
FormError, | ||
>( | ||
context: FormContext<FormSchema, FormError, any>, | ||
subjectRef: MutableRefObject<SubscriptionSubject>, | ||
subjectRef: React.MutableRefObject<SubscriptionSubject>, | ||
stateSnapshot: FormState<FormError>, | ||
prefix = '', | ||
key?: string | number, | ||
|
@@ -404,7 +374,7 @@ export function getFormMetadata< | |
FormValue = Schema, | ||
>( | ||
context: FormContext<Schema, FormError, FormValue>, | ||
subjectRef: MutableRefObject<SubscriptionSubject>, | ||
subjectRef: React.MutableRefObject<SubscriptionSubject>, | ||
stateSnapshot: FormState<FormError>, | ||
noValidate: boolean, | ||
): FormMetadata<Schema, FormError> { | ||
|
@@ -450,7 +420,7 @@ export type FormOptions< | |
* A function to be called before the form is submitted. | ||
*/ | ||
onSubmit?: ( | ||
event: FormEvent<HTMLFormElement>, | ||
event: React.FormEvent<HTMLFormElement>, | ||
context: ReturnType< | ||
BaseFormContext<Schema, FormError, FormValue>['submit'] | ||
>, | ||
|
@@ -465,7 +435,7 @@ export type FormContext< | |
BaseFormContext<Schema, FormError, FormValue>, | ||
'submit' | 'onUpdate' | ||
> & { | ||
submit: (event: FormEvent<HTMLFormElement>) => void; | ||
submit: (event: React.FormEvent<HTMLFormElement>) => void; | ||
onUpdate: ( | ||
options: Partial<FormOptions<Schema, FormError, FormValue>>, | ||
) => void; | ||
|
@@ -479,7 +449,7 @@ export function createFormContext< | |
options: FormOptions<Schema, FormError, FormValue>, | ||
): FormContext<Schema, FormError, FormValue> { | ||
let { onSubmit, ...rest } = options; | ||
const context = createBaseFormContext(rest); | ||
const context = unstable_createFormContext(rest); | ||
|
||
return { | ||
...context, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,10 +294,12 @@ export function useInputValue< | |
return [value, setValue] as const; | ||
} | ||
|
||
export function useControl< | ||
export function unstable_useControl< | ||
Value extends string | string[] | Array<string | undefined>, | ||
>(meta: { key?: Key | null | undefined; initialValue?: Value | undefined }) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const [value, setValue] = useInputValue(meta); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
Comment on lines
+300
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Err.. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the name of the function doesn't start with |
||
const { register, change, focus, blur } = useInputEvent(); | ||
const handleChange = ( | ||
value: Value extends string ? Value : string | string[], | ||
|
@@ -377,13 +379,15 @@ export function useInputControl< | |
}; | ||
} | ||
|
||
export function Control< | ||
export function unstable_Control< | ||
Value extends string | string[] | Array<string | undefined>, | ||
>(props: { | ||
meta: { key?: Key | null | undefined; initialValue?: Value | undefined }; | ||
render: (control: ReturnType<typeof useControl<Value>>) => React.ReactNode; | ||
render: ( | ||
control: ReturnType<typeof unstable_useControl<Value>>, | ||
) => React.ReactNode; | ||
}) { | ||
const control = useControl(props.meta); | ||
const control = unstable_useControl(props.meta); | ||
|
||
return props.render(control); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"references": [ | ||
{ "path": "packages/conform-dom" }, | ||
{ "path": "packages/conform-yup" }, | ||
{ "path": "packages/conform-zod" }, | ||
{ "path": "packages/conform-react" }, | ||
{ "path": "packages/conform-validitystate" } | ||
{ "path": "./packages/conform-dom" }, | ||
{ "path": "./packages/conform-yup" }, | ||
{ "path": "./packages/conform-zod" }, | ||
{ "path": "./packages/conform-react" }, | ||
{ "path": "./packages/conform-validitystate" } | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edmundhung both of these work, but now if we ctrl+click the paths in vscode they goto the file |
||
], | ||
"files": [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this helps comparing to setting an alias on the entry file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you as the author know its unstable, but as the contributor I might not if I don't look at the export boundary (index) that I would read this as stable code