#Check an obj field against the keys of a field from the same object without providing generic.

1 messages · Page 1 of 1 (latest)

wise micaBOT
#

@naive niche Here's a shortened URL of your playground link! You can remove the full link from your message.

nejcr#4575

Preview:```ts
export interface Provider {
fire: () => void
}

export class ProductionProvider implements Provider {
private readonly apiKey: string
constructor(apiKey: string) {
this.apiKey = apiKey
}

fire() {
console.log("Rocket")
}
}

export class DevProvider implements Provider {
...```

frail mauve
#

seem that no good way if using a pure variable variable define statement, but u can try define a function like defineConfig?

naive niche
#

hm ok,

random schooner
#

No way to do this without a generic - satisfies isn't good enough since you have associated types

wise micaBOT
#
Gerrit0#7591

Preview:```ts
...
function defineConfig<
T extends SupportedNetwork

(config: {
providers: Record<T, Provider>
defaultProvider: NoInfer<T>
}) {
return config
}
...```