Skip to content

TSImportType drops the import attributes (options) #231

Closed

Description

@leonidaz

The TSImportType printer drops options, the import attributes of an import type, so they vanish from the output:

type A = import("foo", { with: { type: "json" } });
type B = import("pkg", { with: { "resolution-mode": "require" } }).Mode<string>;

prints

type A = import("foo");
type B = import("pkg").Mode<string>;

resolution-mode changes which declarations TypeScript resolves, so the printed type can mean something else.

import { parse } from '@typescript-eslint/typescript-estree';
import { print } from 'esrap';
import ts from 'esrap/languages/ts';

const source = `type A = import("foo", { with: { type: "json" } });
type B = import("pkg", { with: { "resolution-mode": "require" } }).Mode<string>;
`;
console.log(print(parse(source, { loc: true, range: true }), ts()).code);

typescript-estree puts the attributes on TSImportType.options (an ObjectExpression, or null). The TSImportType visitor writes import(, the argument, and ), and never visits options. The ImportExpression visitor already prints , and options before the ). The same would work here.

Reproduced on esrap 2.3.13 with @typescript-eslint/typescript-estree 8.56.1. #177 is about the same visitor reading argument instead of source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions