Javascript 是否可以在节点模块的编译发行版中输出简化的Typescript类型
我试图在Javascript 是否可以在节点模块的编译发行版中输出简化的Typescript类型,javascript,typescript,babeljs,relay,rollupjs,Javascript,Typescript,Babeljs,Relay,Rollupjs,我试图在*.d.tstypescript文件中创建更简化的输出,这些文件包含在模块代码的捆绑版本中。这些文件是通过涉及typescript编译器、babel和rollup的链生成的。我也在使用relay和graphql,但我认为这不会对问题产生太大影响 例如,在.tsx源代码中,我有如下内容: import { graphql } from 'babel-plugin-relay/macro' // produces some generated code graphql`fragment
*.d.ts
typescript文件中创建更简化的输出,这些文件包含在模块代码的捆绑版本中。这些文件是通过涉及typescript编译器、babel和rollup的链生成的。我也在使用relay和graphql,但我认为这不会对问题产生太大影响
例如,在.tsx
源代码中,我有如下内容:
import { graphql } from 'babel-plugin-relay/macro'
// produces some generated code
graphql`fragment task_model on Task { id message createdAt deadline modifiers { hard medium easy } }`
// There is a generated type for this fragment, but it is a little ugly
import { task_model } from './__generated__/task.graphql'
// We can "correct" the type information and export it with a nicer name
export type Task = Readonly<Omit<task_model & { deadline: string, createdAt: string }, ' $refType'>>
但是,在一个功能强大的IDE中,我可以看到该类型解析为一个更合理的IDE
type Task = {
readonly id: string;
readonly message: string;
readonly createdAt: string;
readonly deadline: string;
readonly modifiers: {
readonly hard: number;
readonly medium: number;
readonly easy: number;
};
}
是否有一些选项或方法可以输出更清晰的人类可读类型解析,而不是描述更正的版本?我认为即使使用该模块的项目没有正确配置以使用它,也能够理解类型信息是很好的
type Task = {
readonly id: string;
readonly message: string;
readonly createdAt: string;
readonly deadline: string;
readonly modifiers: {
readonly hard: number;
readonly medium: number;
readonly easy: number;
};
}