Pass type to function or create type from object

27
May 15, 2019, at 9:10 PM

I have function, in which I need to use type, passed like one of function parameters:

export const buildComponent = (
  { classes }: any,
  urlParameters: urlParametersT,
  headerColumns: any,
  title: string,
  // resourceType: should be type or object 
) =>

I have tried to pass type like this :

  type someType = {
    id: string
    firstName: string
    lastName: string
  } 
  const component = buildComponent(
    { classes },
    urlParameters,
    tableHeaders,
    'Users',
    someType
  )

And have tried to pass object on function and then create a type:

  const component = buildComponent(
    { classes },
    urlParameters,
    tableHeaders,
    'Users',
    {
      id: string
      firstName: string
      lastName: string
      email: string
      password: string
      isActive: boolean
      created: string
      modified: string
    }
  )
export const buildComponent = (
  { classes }: any,
  urlParameters: urlParametersT,
  headerColumns: any,
  title: string,
  resourceType: object
) => {
  type BulletT = resourceType

So, the question is can I somehow pass custom type to function and then use it? Or can I create something like types object and then get type I need from there.

READ ALSO
NodeJS plans to support import/export es6 (es2015) modules

NodeJS plans to support import/export es6 (es2015) modules

I've been looking all over the internet without a clear answer for this

17
Sequelize ordering with nested associations

Sequelize ordering with nested associations

I have an included model where I need to sort by the same property but with two conditionals

43
Node app segfault on Heroku: std::bad_alloc and exit code 134

Node app segfault on Heroku: std::bad_alloc and exit code 134

I am having difficulty understanding this heroku stack traceMy app has been running very well both locally and in Heroku for a few years now

23
socket.io is not working with simple-peer

socket.io is not working with simple-peer

i am willing to build one-to-one video chatroom with Socketio & Simple-Peer and for one-to-one algorithm i used socket

22