@@ -128,14 +128,42 @@ type InferPropType<T> = [T] extends [null]
128
128
: V
129
129
: T
130
130
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
+ */
131
140
export 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
133
143
[ K in keyof Pick < O , RequiredKeys < O > > ] : InferPropType < O [ K ] >
134
144
} & {
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
136
147
[ K in keyof Pick < O , OptionalKeys < O > > ] ?: InferPropType < O [ K ] >
137
148
}
138
149
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
+
139
167
const enum BooleanFlags {
140
168
shouldCast ,
141
169
shouldCastTrue
0 commit comments