#Make requiremments for variable type
23 messages · Page 1 of 1 (latest)
you could try object & Record<keyof K, {}>
ty
This makes all of the properties unknown, but for my usecase I could make them all strings, so its fine
type ToString<T> = T extends Date
? string
: T extends object
? PropertiesToString<T>
: string
type PropertiesToString<T> = {
[K in keyof T]: ToString<T[K]>
}
wait what
can you show your code?
export function dbStore<X> (
stores: Required<object & Record<keyof X, {}>>,
...path: string[]
): X {
// redacted for brevity
return store
}
const profile = dbStore({
username: preload.username ?? "Loading...",
avatar: preload.avatar ?? defaultAvatar,
banner: preload.banner ?? defaultBanner,
}, id)
are you sure your <> are balanced?
I'm pretty sure
stores: <X extends object & Record<keyof X, {}>>,
The error is on the comma, and also it thinks stores is a function now?
oh... my bad
export function dbStore<X extends object & Record<keyof X, {}>> (
stores: Required<X>,
...path: string[]
): X {
// redacted for brevity
return store
}
something like this
Preview:ts export function dbStore<X> ( stores: <X extends object & Record<keyof X, {}>>, ...path: string[] ): X { // redacted for brevity //@ts-ignore return stores // note: I'm using ts-ignore here in the actual code aswell // I'm completely fine with that ...
You can choose specific lines to embed by selecting them before copying the link.