Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
typescript: type string is not assignable error?

I have a simple Fonts file I am importing with just info right now that contains Arial but will contain others later on.

Fonts.ts

interface Font {
    [key: string]: {
        'full': string,
        'trial': string
    }
}

interface FontList {
    [key: string]: Font
}

export const FONT_LIST: FontList = {
    'Arial':
        {

            'Regular': {
                'full': 'blahblah',
                'trial': 'blahblah'
            },
            'Bold': {
                'full': 'blahblah',
                'trial': 'blahblah'
            },

        },
}

In a function, I am trying to get the value based on their entitlement

import { Fonts } from './Fonts'

function foo(postscriptName:string, style: string) {
     
    const entitlement = "full";

    const selectedFont = FONT_LIST[postscriptName][style][entitlement];

    return selectedFont;
}

For selectedFont, I am getting a TS error of: Type 'string' is not assignable to type '{ family: string; style: string; postscriptName: string; }'

to debug, I even tried selectedFont = FONT_LIST['Arial']['Bold']['full]; to ensure values are there but I am getting the same error.
I am expecting to get back "blahblah".

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda