我有一个函数,我需要使用类型,就像函数参数之一一样传递:
export const buildComponent = (
{ classes }: any,
urlParameters: urlParametersT,
headerColumns: any,
title: string,
// resourceType: should be type or object
) =>
我试图通过这样的类型:
type someType = {
id: string
firstName: string
lastName: string
}
const component = buildComponent(
{ classes },
urlParameters,
tableHeaders,
'Users',
someType
)
并且尝试将对象传递给函数,然后创建一个类型:
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
所以,问题是我可以以某种方式将自定义类型传递给函数然后使用它吗?或者我可以创建类似类型对象的东西,然后从那里获取我需要的类型。