Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda