Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active October 6, 2020 12:17
Show Gist options
  • Save wmakeev/4504d5d6ade2035c42ab3958d988dd6d to your computer and use it in GitHub Desktop.
Save wmakeev/4504d5d6ade2035c42ab3958d988dd6d to your computer and use it in GitHub Desktop.
TypeScript questions #typescript #question
interface ModelAttributes {
  [name: string]: string | number
}

interface Agent {
  id: string
  created_date: Date
  name: string
  city: string | null
  email: string | null
  phone: string | null
  sales_amount: number
}

type AgentAttributes<T extends Agent> = {
  [P in keyof T]: ModelAttributes[P] // how to infer field value type from ModelAttributes
}

Playgrownd

const modelAttributes: Pick<ModelAttributes, keyof Agent> = {
  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment