interface Link {
href: string;
}
type MandatoryPaginationLinks = {
[key in 'first' | 'last']: Link;
}
type OptionalPaginationLinks = {
[key in 'prev' | 'next']: Link | null;
}
type PaginationLinks = MandatoryPaginationLinks & OptionalPaginationLinks;
type AdditionalLinks = {
[key: string]: Link;
};
type Links = PaginationLinks & AdditionalLinks;
const links: Links = {
self: {
href: 'asdf'
},
prev: null,
next: {
href: '',
},
first: {
href: 'asdf'
},
last: {
href: 'asdf'
}
};
I have a Links type.
first and last properties have to be set and must be Link
. prev and next properties can be whether a Link or null. Optional links must have Link
type. The problem is that Typescript sees 'first', 'last', 'prev' and 'next' as string
so the expression is always mapped to AdditionalLinks
type. I want to have a solution to exclude these four strings from string
type.
For example (not working):
type AdditionalLinks = {
[key: Omit<string, 'first' | 'last' | 'prev' | 'next'>]: Link;
};