type Role = 'User' | 'Admin' | 'Owner';
type RoleNum = 0 | 1 | 2;
//In the first example here, we are defining a 'Role' type and a generic R. Ideally we would be able to break down the union type passed into R to create the 'RoleNum' type. Instead of parameters, the data is passed in directly as the type.
function test<R extends string>(): [Record<R, number>, RoleNum] {
//const [first, ...rest] = params;
//const enumerated = typeof first === 'boolean' ? first : undefined;
const result = {} as Record<R, number>;
const unionType: number[] = [];
return [result, unionType];
}
//In this example, we nix the R type all together and pass in the hard coded string values. This could be better because it includes an array that can be iterated through
function test(...role: string[] ): [Record<R, number>, RoleNum] {
//const [first, ...rest] = params;
//const enumerated = typeof first === 'boolean' ? first : undefined;
const result = {} as Record<R, number>;
const unionType: number[] = [];
return [result, unionType];
}
type Role = 'User' | 'Admin' | 'Owner';
type RoleNum = 0 | 1 | 2;
//In the first example here, we are defining a 'Role' type and a generic R. Ideally we would be able to break down the union type passed into R to create the 'RoleNum' type. Instead of parameters, the data is passed in directly as the type.
function test<R extends string>(): [Record<R, number>, RoleNum] {
//const [first, ...rest] = params;
//const enumerated = typeof first === 'boolean' ? first : undefined;
const result = {} as Record<R, number>;
const unionType: number[] = [];
return [result, unionType];
}
//In this example, we nix the R type all together and pass in the hard coded string values. This could be better because it includes an array that can be iterated through
function test(...role: string[] ): [Record<R, number>, RoleNum] {
//const [first, ...rest] = params;
//const enumerated = typeof first === 'boolean' ? first : undefined;
const result = {} as Record<R, number>;
const unionType: number[] = [];
return [result, unionType];
}