假设我有以下示例代码.这个共享组件的使用将有不同的有效name
props ,这取决于组件的使用位置.是否可以动态导入TYPE_IMPORT
,以便在不同的上下文中使用时导入适当的类型.
// example/import/path1.ts
export type TYPE_IMPORT = "foo" | "bar" | "testing1" | "testing2";
// example/import/path2.ts
export type TYPE_IMPORT = "pikachu" | "charmander" | "testing3" | "testing4";
import { TYPE_IMPORT } from 'example/import/path1';
interface IFooProps {
name: TYPE_IMPORT;
}
export const FooComponent = (props: IFooProps ) => {
const { name} = props;
return (
<svg>
<use href={`#${name}`} />
</svg>
);
};