Magek Framework
    Preparing search index...

    Function createInstance

    • Creates an instance of the given class from the given raw object.

      Type Parameters

      • T

      Parameters

      • instanceClass: Class<T>

        The class of the instance to create

      • rawObject: Record<string, any>

        The raw object to use as source

      Returns T

      An instance of the given class

      import { createInstance } from '@magek/common'
      import { User } from './entities/user'

      const rawUser = {
      id: '123',
      name: 'John Doe',
      }

      const user = createInstance(User, rawUser)

      console.log(user.id) // Prints '123'
      console.log(user.name) // Prints 'John Doe'