Skip to content

Instantly share code, notes, and snippets.

@fimars
Created October 25, 2024 03:11
Show Gist options
  • Save fimars/0ce69c5c90b130a6dd9116936654e424 to your computer and use it in GitHub Desktop.
Save fimars/0ce69c5c90b130a6dd9116936654e424 to your computer and use it in GitHub Desktop.
FIX `A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1170)`
type PlanName = 'free' | 'starter' | 'growth' | 'plus'
type PlanDuration = 'monthly' | 'annually'
type BillingPlanEvent = `billing_${PlanName}_${PlanDuration}_click`
type GuidacneStep = 1 | 2 | 3
type GuidanceEvent = `guidance_step${GuidacneStep}_next_click`
// A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1170)
// Fix?
export type UserEventPayload = {
home_tasks_click: {}
home_tasks_toggle: {}
billing_enter: {}
billing_leave: {}
apply_flash_sale: {
apply: 'on' | 'off'
}
billing_demo_click: {}
billing_customer_support_click: {}
} & {
// 1
[K in BillingPlanEvent]: {}
} & {
// 2
[K in GuidanceEvent]: {}
}
export type UserEventKey<E> = E extends keyof UserEventPayload ? E : never
export type UserEventProperties<E extends keyof UserEventPayload> =
UserEventPayload[E]
@fimars
Copy link
Author

fimars commented Oct 25, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment