Instead of giving a title, I find it easier to demonstrate what I need:
type Foo = "bar" | "baz";
interface Consistency {
foo: Foo;
fooTemplate: `${Foo} in a template`;
}
// This should compile (and it does)
const valid1: Consistency = {
foo: "bar",
fooTemplate: "bar in a template",
}
const valid2: Consistency = {
foo: "baz",
fooTemplate: "baz in a template",
}
// This should NOT compile (but it does)
const invalid1: Consistency = {
foo: "bar",
fooTemplate: "baz in a template",
}
const invalid2: Consistency = {
foo: "baz",
fooTemplate: "bar in a template",
}
You can experiment with this example here. I attempted to modify Consistency
to
interface Consistency {
foo: Foo;
fooTemplate: `${foo} in a template`; //lowercase foo
}
but that didn't work. Is there a way to make the compiler throw an error in the invalid cases?