#dynamic type based on object array
16 messages · Page 1 of 1 (latest)
You can do this way:
const obj = [
{ name: 'test1' },
{ name: 'test2' },
{ name: 'test3' },
] as const;
type Test = (typeof obj)[number]['name'];
const obj = [
{ name: 'test1' },
{ name: 'test2' },
{ name: 'test3' },
] as const
type Obj = typeof obj
type Name = Obj[number]['name']
// ^? - type Name = "test1" | "test2" | "test3"
Handbook
im not sure var const will work im my situation
export type HonoPassportStrategy<TUser> = {
name: string;
authenticate: (ctx: Context) => Promise<TUser> | TUser;
};
export type HonoPassportOptions<TUser, TSessionUser> = {
strategies: HonoPassportStrategy<TUser>[];
serializeUser?: (user: TUser) => TSessionUser | Promise<TSessionUser>;
deserializeUser?: (user: TSessionUser) => TUser | Promise<TUser>;
};
export type HonoPassportReturn<TUser, TSessionUser> = {
initialize: () => MiddlewareHandler<HonoPassportEnv<TUser, TSessionUser>>;
login: (
strategyName: string,
) => MiddlewareHandler<HonoPassportEnv<TUser, TSessionUser>>;
logout: () => MiddlewareHandler<HonoPassportEnv<TUser, TSessionUser>>;
};
this might provide some more info
can i restrict strategyName: string to the name's from the strategies array
Not unless you specify what names are allowed.
ye that is user side config stuff