From 2f91db30cda5c315ed3e4d20800b55721b0cb17c Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 28 Jun 2021 11:39:24 -0400 Subject: [PATCH] feat(sfc): support using declared interface or type alias with defineProps() --- .../__snapshots__/compileScript.spec.ts.snap | 76 +++++++++++++++++++ .../__tests__/compileScript.spec.ts | 56 ++++++++++++++ packages/compiler-sfc/src/compileScript.ts | 51 +++++++++++-- 3 files changed, 175 insertions(+), 8 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index b1d54478b3b..9553ab1250e 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -780,6 +780,63 @@ return { emit } })" `; +exports[`SFC compile + `) + assertCode(content) + expect(content).toMatch(`x: { type: Number, required: false }`) + expect(bindings).toStrictEqual({ + x: BindingTypes.PROPS + }) + }) + + test('defineProps w/ exported interface', () => { + const { content, bindings } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`x: { type: Number, required: false }`) + expect(bindings).toStrictEqual({ + x: BindingTypes.PROPS + }) + }) + + test('defineProps w/ type alias', () => { + const { content, bindings } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`x: { type: Number, required: false }`) + expect(bindings).toStrictEqual({ + x: BindingTypes.PROPS + }) + }) + + test('defineProps w/ exported type alias', () => { + const { content, bindings } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`x: { type: Number, required: false }`) + expect(bindings).toStrictEqual({ + x: BindingTypes.PROPS + }) + }) + test('withDefaults (static)', () => { const { content, bindings } = compile(`