Skip to content

Commit

Permalink
fix(vue): add correct v-model type (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdebeasi authored Mar 30, 2023
1 parent caa4732 commit 2dc273e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent>
});

expect(output).toEqual(`
export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent>('my-component', undefined, [
export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent, Components.MyComponent["value"]>('my-component', undefined, [
'value',
'ionChange'
],
Expand Down Expand Up @@ -139,7 +139,7 @@ export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent>
});

expect(output).toEqual(`
export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent>('my-component', undefined, [
export const MyComponent = /*@__PURE__*/ defineContainer<Components.MyComponent, Components.MyComponent["value"]>('my-component', undefined, [
'value',
'ionChange'
],
Expand Down
10 changes: 6 additions & 4 deletions packages/vue-output-target/src/generate-vue-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ export const createComponentDefinition =
props = [...props, ...cmpMeta.events.map((event) => `'${event.name}'`)];
}

let templateString = `
export const ${tagNameAsPascal} = /*@__PURE__*/ defineContainer<${importTypes}.${tagNameAsPascal}>('${cmpMeta.tagName}', ${importAs}`;

const componentType = `${importTypes}.${tagNameAsPascal}`;
const findModel =
componentModelConfig && componentModelConfig.find((config) => config.elements.includes(cmpMeta.tagName));
const modelType = findModel !== undefined ? `, ${componentType}["${findModel.targetAttr}"]` : '';

let templateString = `
export const ${tagNameAsPascal} = /*@__PURE__*/ defineContainer<${componentType}${modelType}>('${cmpMeta.tagName}', ${importAs}`;

if (props.length > 0) {
templateString += `, [
${props.length > 0 ? props.join(',\n ') : ''}
]`;
/**
* If there are no props,
* but but v-model is stil used,
* but v-model is still used,
* make sure we pass in an empty array
* otherwise all of the defineContainer properties
* will be off by one space.
Expand Down

0 comments on commit 2dc273e

Please sign in to comment.