primevue
primevue copied to clipboard
Knob: Incorrect TypeScript Definition for valueTemplate (not supporting plain strings)
Describe the bug
The valueTemplate
prop in the Knob
component has an incorrect TypeScript type definition:
valueTemplate?: (val: number) => string | string | undefined;
This type forces the prop to only accept functions, as string | undefined
is interpreted as the return type of the function. This makes it impossible to assign a plain string
to the valueTemplate
prop, which is a valid use case according to the documentation.
Reproducer
https://stackblitz.com/edit/primevue-4-ts-vite-issue-template-bpnzqf?file=src%2FApp.vue,src%2FKnobPropsExample.ts
PrimeVue version
4.2.3
Vue version
4.x
Language
TypeScript
Build / Runtime
Vite
Browser(s)
No response
Steps to reproduce the behavior
- Use the
Knob
component in a TypeScript project. - Attempt to pass a plain string to the
valueTemplate
prop:<Knob v-model="knobValue" :step="10" :min="-50" :max="50" valueTemplate="{value}%" />
- Observe the TypeScript error, which requires a function instead of a string.
Expected behavior
The valueTemplate
prop should accept:
- A function that returns
string
. - A plain
string
value. - Or remain undefined.