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

159
Visualizações
Can I reuse inline/hardcoded type from component.d.ts file

I want to selectively pass props to the library component.

Library has created an inline type by hardcoding multiple values.

I interest of my code upgrading automatically with additions to the library defined type can I reuse those inline values without recreating them

Inside library --> component.d.ts file has

export interface TooltipProps {
  ...manyOtherProps,
  placement?: | 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
}

I tried some attempts with keyof and valueof


type ValueOf<T> = T[keyof T];
type PlacementStrings = ValueOf<TooltipProps>
interface JustPlacement { 
  placement: "top"
}

type PlacementStringsKeys = keyof TooltipProps & keyof JustPlacement

type stpls = ValueOf<PlacementStringsKeys>

But not getting the needed thing.

which would be without rewriting it

interface CustomTooltipProps {
  placement?: | 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use the Pick helper to create a new object type including all keys/values where the key is assignable to the specified type:

// mylib.ts
export interface TooltipProps {
  foo: "bar";
  placement?: | 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
}

// otherfile.ts
import type { TooltipProps } from "./mylib";

type CustomTooltipProps = Pick<TooltipProps, "placement">;

// this is expanded into the following:
type CustomTooltipProps = {
    placement?: "bottom-end" | "bottom-start" | "bottom" | "left-end" | "left-start" | "left" | "right-end" | "right-start" | "right" | "top-end" | "top-start" | "top" | undefined;
}

TypeScript Playground Link

about 4 years ago · Juan Pablo Isaza Relatório
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