I am working with an enum
export const trackingKeys = {
Form: 'form',
Video: 'video',
} as const
I also have a type that assigns a type property to each key
export type TrackingPropertiesByKey = {
[trackingKeys.Form]: { bar : number }
[trackingKeys.Video]: { foo : boolean }
}
Additionally, there is a track function defined
export type TrackingEventKey =
typeof trackingKeys[keyof typeof trackingKeys]
const track = <T extends TrackingEventKey>(
event: TrackingEventKey,
properties?: TrackingPropertiesByKey[T]
) => trackFromLib(event, properties)
When using
track(trackingKeys.Form, {foo : true, bar: 1 })
, no error is thrown.
The current type definition looks like this:
const track: <TrackingEventKey>(event: TrackingEventKey, properties?: {
bar: number;
} | {
foo: boolean;
}) => void
However, I want the properties parameter to be more specific like so: { bar : number }