@@ -128,14 +128,42 @@ type InferPropType<T> = [T] extends [null]
128128 : V
129129 : T
130130
131+ /**
132+ * Extract prop types from a runtime props options object.
133+ * The extracted types are **internal** - i.e. the resolved props received by
134+ * the component.
135+ * - Boolean props are always present
136+ * - Props with default values are always present
137+ *
138+ * To extract accepted props from the parent, use {@link ExtractPublicPropTypes}.
139+ */
131140export type ExtractPropTypes < O > = {
132- // use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to support IDE features
141+ // use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to
142+ // support IDE features
133143 [ K in keyof Pick < O , RequiredKeys < O > > ] : InferPropType < O [ K ] >
134144} & {
135- // use `keyof Pick<O, OptionalKeys<O>>` instead of `OptionalKeys<O>` to support IDE features
145+ // use `keyof Pick<O, OptionalKeys<O>>` instead of `OptionalKeys<O>` to
146+ // support IDE features
136147 [ K in keyof Pick < O , OptionalKeys < O > > ] ?: InferPropType < O [ K ] >
137148}
138149
150+ type PublicRequiredKeys < T > = {
151+ [ K in keyof T ] : T [ K ] extends { required : true } ? K : never
152+ } [ keyof T ]
153+
154+ type PublicOptionalKeys < T > = Exclude < keyof T , PublicRequiredKeys < T > >
155+
156+ /**
157+ * Extract prop types from a runtime props options object.
158+ * The extracted types are **public** - i.e. the expected props that can be
159+ * passed to component.
160+ */
161+ export type ExtractPublicPropTypes < O > = {
162+ [ K in keyof Pick < O , PublicRequiredKeys < O > > ] : InferPropType < O [ K ] >
163+ } & {
164+ [ K in keyof Pick < O , PublicOptionalKeys < O > > ] ?: InferPropType < O [ K ] >
165+ }
166+
139167const enum BooleanFlags {
140168 shouldCast ,
141169 shouldCastTrue
0 commit comments