Created a function that returns a Valibot type but not getting intellisense for types #531
-
Hi 👋 I created this function: export const getPluginBaseSchema = (
options: Parameters<typeof v.object>[0]
) => {
return v.optional(
v.merge(
[
v.object(options),
v.object({
// ...
}),
],
v.never()
),
{}
)
} And I use it like this: /** [View on NPM](https://npmjs.com/package/remark-frontmatter). */
remarkFrontmatter: getPluginBaseSchema({
/** @default true */
enable: v.optional(v.boolean(), true),
/** **Important**: Don't change! Only `"yaml"` is supported for now. */
lang: v.optional(
v.union([v.literal("yaml")]),
"yaml"
),
options: v.optional(
v.special<RemarkFrontmatterCustomOptions>(
() => true
)
),
}),
/** [View on NPM](https://npmjs.com/package/remark-frontmatter-yaml). */
remarkFrontmatterYaml: getPluginBaseSchema({
/** @default true */
enable: v.optional(v.boolean(), true),
options: v.optional(
v.special<RemarkFrontmatterYamlCustomOptions>(
() => true
)
),
}), The problem is that I'm not getting IntelliSense stuff at all (all is |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Apr 17, 2024
Replies: 1 comment 5 replies
-
It may work if you use a generic: export const getPluginBaseSchema = <TEntries extends v.ObjectEntries>(
options: TEntries
) => {
return v.optional(
v.merge(
[
v.object(options),
v.object({
// ...
}),
],
v.never()
),
{}
)
} |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
babakfp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It may work if you use a generic: