Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__VLS_WithTemplateSlots breaks api-extractor #2237

Closed
nborko opened this issue Dec 20, 2022 · 2 comments
Closed

__VLS_WithTemplateSlots breaks api-extractor #2237

nborko opened this issue Dec 20, 2022 · 2 comments

Comments

@nborko
Copy link

nborko commented Dec 20, 2022

We use api-extractor to roll up .d.ts files to a single file, as well as for generating a document model JSON file.

api-extractor now generates a warning for every SFC that uses slots, e.g.

(ae-forgotten-export) The symbol "__VLS_WithTemplateSlots_31" needs to be exported by the entry point index.d.ts

I don't want to ignore this message, because a missing export in the rolled up .d.ts file will break builds, so we want the build process to error. But _VLS_WithTemplateSlots is a synthetic byproduct of vue-tsc, and not at all useful in the final .d.ts.

Is there a workaround, other than ignoring ae-forgotten-export messages?

@johnsoncodehk
Copy link
Member

It is not purely a by-product, it allows your component slots to be recognized via .d.ts by Volar to support slots intellisense and type check.

But if you don't want to build slots types, you can have a special tsconfig with config "skipTemplateCodegen": true just for build dts.

tsconfig.dts.json

{
	"extends": "./tsconfig.json",
	"vueCompilerOptions": {
		"skipTemplateCodegen": true
	}
}

$ vue-tsc --noEmit -p tsconfig.dts.json

@nborko
Copy link
Author

nborko commented Dec 22, 2022

You're right, "byproduct" does have a negative connotation, and "product" would have sufficed.

However, including that option did not change the emitted d.ts files for me. Here is my modified tsconfig.dts.json file as you suggest:

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "declaration": true,
        "emitDeclarationOnly": true,
        "declarationDir": "build"
    },
    "vueCompilerOptions": {
        "skipTemplateCodegen": true
    }
}

It still emits the code:

declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{

I actually do want the DefineComponent to be emitted, however, so that the imported values can be typed correctly when passed to my app.component calls in the module that imports this library. I find that really helpful, and it has worked great in the past until 1.0.10 when it went all pear shaped and forced me to @ts-expect-error like crazy.

But back to the issue, since __VLS_WithTemplateSlots is declared as a separate type 31 times in my component library dts files, api-extractor mangles the name in the rolled up dts file, and they are not exported. Manually slapping "export" in front of the type definition in the pre-rolledup files doesn't really help, because they're not re-exported at higher levels.

This isn't to say that I can't just ignore the exit code from api-extractor and continue by build anyway, because it doesn't prevent the dts files from being generated and working where needed, but with all the messaging spam it makes it hard to find actual issues. Maybe this is a failing of api-extractor and I should just forego rolling up the .d.ts files, but it's a great linting tool for preventing issues when generating documenattion with typedoc.

So if there was a way to disable this Volar-specific wrapper and just generate the actual DefineComponent type, I believe that would 100% fix the issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants