Apologies for the poorly titled post; summarizing my query into one sentence was challenging.
I'm including the current code I have, as I believe it should be easy to understand.
// Constants that define columns
const columns = ["a", "b", "c"] as const
// Defining editable columns using a subset of the columns
type EditableColumns = readonly (typeof columns[number])[]
// Specify which columns are editable
const editableColumns: EditableColumns = ["a", "b"] as const
type Props<T> = { data: readonly T[], editableColumns: EditableColumns }
// The goal is to add extra info only to editable columns and exclude others
type Foo<U, T extends Props<U> = Props<U>> = {
[key in typeof columns[number]]: key extends T["editableColumns"][number]
? {
readonly column: key
readonly row: U
readonly extraInfo: "HELLO"
}
: {
readonly column: key
readonly row: U
}
}
let foo = {} as Foo<string>
// Currently, all columns receive the extra info,
// even though 'foo.c' shouldn't. Hover over 'foo.c' to verify.
foo.a
foo.b
foo.c
// How can I ensure only 'a' and 'b' get the extra info while excluding 'c'?