-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
🔎 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:
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. 😃