Can I reuse inline/hardcoded type from component.d.ts file
Solution 1:
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