#How to force given type to be record of value types of previous type values?
1 messages · Page 1 of 1 (latest)
interface Foo {
a: string;
b: number;
}
interface Bar {
as: string;
bb: number;
}
type OnlyMatching<T> = Record<string, T[keyof T]>;
interface Type<A, B extends OnlyMatching<A>> {
a: A;
b: B;
}
type Result = Type<Foo, Bar>;
// ^^^
// Type 'Bar' does not satisfy the constraint 'OnlyMatching<Foo>'.
// Index signature for type 'string' is missing in type 'Bar'.
Interfaces don't have implicit index signatures, if you change Bar to a type it works.
I see makes sense then I guess