Skip to content

Commit

Permalink
feat(core): fix typings for ValueFormat context support
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Sep 7, 2021
1 parent e0adf5a commit 828e06b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions packages/core/index.d.ts
Expand Up @@ -382,18 +382,18 @@ declare module '@nivo/core' {
y: number
}

export type ValueFormat<Value, Context = never> =
export type ValueFormat<Value, Context = void> =
| string // d3 formatter
// explicit formatting function
| Context extends never
| Context extends void
? (value: Value) => string
: (value: Value, context: Context) => string
export function getValueFormatter<Value, Context = never>(
format?: ValueFormat<Value>
): Context extends never ? (value: Value) => string : (value: Value, context: Context) => string
export function useValueFormatter<Value, Context = never>(
format?: ValueFormat<Value>
): Context extends never ? (value: Value) => string : (value: Value, context: Context) => string
export function getValueFormatter<Value, Context = void>(
format?: ValueFormat<Value, Context>
): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string
export function useValueFormatter<Value, Context = void>(
format?: ValueFormat<Value, Context>
): Context extends void ? (value: Value) => string : (value: Value, context: Context) => string

export type PropertyAccessor<Datum, Value> =
// path to use with `lodash.get()`
Expand Down
2 changes: 1 addition & 1 deletion packages/tooltip/src/BasicTooltip.tsx
Expand Up @@ -17,7 +17,7 @@ interface BasicTooltipProps {
export const BasicTooltip = memo<BasicTooltipProps>(
({ id, value: _value, format, enableChip = false, color, renderContent }) => {
const theme = useTheme()
const formatValue = useValueFormatter(format)
const formatValue = useValueFormatter<number | string | Date>(format)

let content: JSX.Element
if (typeof renderContent === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion packages/tooltip/src/Tooltip.tsx
Expand Up @@ -4,7 +4,7 @@ import { TooltipStateContextData, TooltipStateContextDataVisible } from './conte

export const isVisibleTooltipState = (
state: TooltipStateContextData
): state is TooltipStateContextDataVisible => state.isVisible === true
): state is TooltipStateContextDataVisible => state.isVisible

export const Tooltip = () => {
const state = useTooltipState()
Expand Down

0 comments on commit 828e06b

Please sign in to comment.