Skip to content

[API] getImpliedNodeFormatForFile can't be used because the first argument is of an internal type #56852

@ericmorand

Description

@ericmorand

🔎 Search Terms

I searched for getImpliedNodeFormatForFile. The issues I found are not related to this issue.

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about TypeScript API.

⏯ Playground Link

No response

💻 Code

const containingFile = 'foo.ts';

const mode = ts.getImpliedNodeFormatForFile(
    containingFile, // TS22345: Argument of type `string` is not assignable to parameter of type `Path`
undefined,
    ts.sys,
    {}
);

🙁 Actual behavior

The mentionned code does not compile because getImpliedNodeFormatForFile expects the first argument to be of a type that is not publicly accessible or instantiable:

type Path = string & {
    __pathBrand: any;
};

There seems to be some factories to construct a Path in the code base of the API, but they are not exposed.

🙂 Expected behavior

The mentionned code does compile, either because getImpliedNodeFormatForFile expects the first argument to be of a type string, or because there is a way to construct an instance of Path.

Additional information about the issue

Interestingly enough, even the developers of the official TypeScript plugin of Rollup did struggle with this issue:

https://github.com/rollup/plugins/blob/33174f956304ab4aad4bbaba656f627c31679dc5/packages/typescript/src/index.ts#L129

ts.getImpliedNodeFormatForFile(
  // @ts-expect-error
  containingFile,
  undefined, // eslint-disable-line no-undefined
  { ...ts.sys, ...formatHost },
  parsedOptions.options
)

They unfortunately didn't consider opening an issue here, so here I am. 😃

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions