Skip to content

Commit

Permalink
feat: $attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Nov 19, 2024
1 parent 105d1d7 commit 15a8ddc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
if (options.propsAssignName) {
ctx.addLocalVariable(options.propsAssignName);
}
ctx.addLocalVariable("$attrs");
ctx.addLocalVariable('$el');
ctx.addLocalVariable('$refs');

Expand Down Expand Up @@ -91,11 +92,12 @@ function* generateSlotsType(options: TemplateCodegenOptions, ctx: TemplateCodege
}

function* generateInheritedAttrs(ctx: TemplateCodegenContext): Generator<Code> {
yield 'var __VLS_inheritedAttrs!: {}';
yield 'let __VLS_inheritedAttrs!: {}';
for (const varName of ctx.inheritedAttrVars) {
yield ` & typeof ${varName}`;
}
yield endOfLine;
yield `var $attrs!: Partial<typeof __VLS_inheritedAttrs> & Record<string, unknown>${endOfLine}`;
}

function* generateRefs(ctx: TemplateCodegenContext): Generator<Code> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import { type AnchorHTMLAttributes, type ReservedProps, useAttrs } from 'vue';
import { exactType } from '../../shared';
type InheritedAttrs = Partial<AnchorHTMLAttributes & ReservedProps> & Record<string, unknown>;
const attrs = useAttrs();
exactType(attrs, {} as Partial<AnchorHTMLAttributes & ReservedProps> & Record<string, unknown>);
exactType(attrs, {} as InheritedAttrs);
</script>

<template>
<a></a>
<a>{{ exactType($attrs, {} as InheritedAttrs) }}</a>
</template>

0 comments on commit 15a8ddc

Please sign in to comment.