primevue icon indicating copy to clipboard operation
primevue copied to clipboard

Knob: Incorrect TypeScript Definition for valueTemplate (not supporting plain strings)

Open StealthC opened this issue 3 months ago • 0 comments

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

  1. Use the Knob component in a TypeScript project.
  2. Attempt to pass a plain string to the valueTemplate prop:
    <Knob v-model="knobValue" :step="10" :min="-50" :max="50" valueTemplate="{value}%" />
    
  3. Observe the TypeScript error, which requires a function instead of a string.

Expected behavior

The valueTemplate prop should accept:

  1. A function that returns string.
  2. A plain string value.
  3. Or remain undefined.

StealthC avatar Nov 23 '24 01:11 StealthC