Let's talk about titles. Well, maybe not this one.
I tried to come up with a good title, but it didn't work out as planned.
In my coding journey, I have created a cool interface called DefaultTheme
:
export interface DefaultTheme {
colors: {
background: '#fff'
text: '#1d1d1f'
secondaryText: '#515154'
primary: '#06c'
}
pages: PageTheme
}
Next, I decided to extend this interface with another one called PageTheme
for specific pages:
export interface PageTheme {
sensei: {
colors: {
background: '#fff'
text: '#1d1d1f'
secondaryText: '#515154'
background: '#06090D' //different
}
}
}
But here's the challenge - I don't need all the properties from DefaultTheme
, just want to modify the colors
section by changing the background
color.
This led me to experiment with the following approach:
export interface PageTheme {
sensei: {
colors: DefaultTheme & {
background: '#06090D'
}
}
}
As I attempted to merge the colors into actual objects, I encountered an error:
const defaultTheme: Omit<DefaultTheme, 'pages'> = {
colors: {
background: '#fff',
text: '#1d1d1f',
secondaryText: '#515154',
primary: '#06c',
},
}
const pagesThemes: PageTheme = {
sensei: {
colors: {
...defaultTheme.colors,
background: '#06090D', // ERROR: Type string is not assignable to type 'never'.
},
},
}
The issue arises when trying to redefine the background color for
pagesThemes.sensei.colors.background
, resulting in a Type string is not assignable to type 'never'
error.
All I really want to achieve is to spread my default values and only update the ones that are different.