Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'. ( Typescript )

Как правильно написать функцию getColors на Typescript ?

export interface Palette {
    100?: string
    200?: string
    300?: string
    400?: string
    500?: string
    600?: string
    700?: string
    800?: string
    900?: string
}

export interface Colors {
    white: string
    black: string
    text: Palette
}

export const colors: Colors = {
    white: '#fff',
    black: '#000',

    text: {
        100: '#f6f6f6',
        200: '#eeeeee',
        300: '#c8c8cc',
        400: '#b3b3bb',
        500: '#8d929a',
        600: '#8a8e94',
        700: '#6b6e74',
        800: '#525252',
        900: '#1a1a1a'
    }
}

type S =
    | 'text'
    | 'white'
    | 'black'

type E = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900

export const getColor = (type: S, number: E): string => {
    if (!number && (type === 'white' || type === 'black')) {
        return colors[type]
    }
    if (number && type) {
        return colors[type]
    }
    return ''
}

введите сюда описание изображения


Ответы (0 шт):