export interface Emits { (e: 'foo' | 'bar'): void }
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
expose()
export type Emits = { (e: 'foo' | 'bar'): void }
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
expose()
interface Emits { (e: 'foo' | 'bar'): void }
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
expose()
export type Emits = (e: 'foo' | 'bar') => void
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
expose()
type Emits = (e: 'foo' | 'bar') => void
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
expose()
type Emits = { (e: 'foo' | 'bar'): void }
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
expose()
"import { defineComponent as _defineComponent } from 'vue'
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\", \\"baz\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\", \\"baz\\"],
setup(__props, { expose, emit }: { emit: ({(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}), expose: any, slots: any, attrs: any }) {
expose()
"import { defineComponent as _defineComponent } from 'vue'
export default /*#__PURE__*/_defineComponent({
- emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
+ emits: [\\"foo\\", \\"bar\\"],
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
expose()
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: false }
- } as unknown as undefined,
- setup(__props: { x?: number }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: false }
- } as unknown as undefined,
- setup(__props: { x?: number }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: false }
- } as unknown as undefined,
- setup(__props: { x?: number }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
literalUnionMixed: { type: [String, Number, Boolean], required: true },
intersection: { type: Object, required: true },
foo: { type: [Function, null], required: true }
- } as unknown as undefined,
- setup(__props: {
- string: string
- number: number
- boolean: boolean
- object: object
- objectLiteral: { a: number }
- fn: (n: number) => void
- functionRef: Function
- objectRef: Object
- array: string[]
- arrayRef: Array<any>
- tuple: [number, number]
- set: Set<string>
- literal: 'foo'
- optional?: any
- recordRef: Record<string, null>
- interface: Test
- alias: Alias
- method(): void
-
- union: string | number
- literalUnion: 'foo' | 'bar'
- literalUnionNumber: 1 | 2 | 3 | 4 | 5
- literalUnionMixed: 'foo' | 1 | boolean
- intersection: Test & {}
- foo: ((item: any) => boolean) | null
- }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: false }
- } as unknown as undefined,
- setup(__props: { x?: number }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
foo: { type: String, required: false },
bar: { type: Number, required: false },
baz: { type: Boolean, required: true }
- }, { ...defaults }) as unknown as undefined,
- setup(__props: {
+ }, { ...defaults }),
+ setup(__props: any, { expose }) {
+ expose()
+
+const props = __props as {
foo?: string
bar?: number
baz: boolean
- }, { expose }) {
- expose()
-
-const props = __props
+ }
return { props, defaults }
bar: { type: Number, required: false },
baz: { type: Boolean, required: true },
qux: { type: Function, required: false, default() { return 1 } }
- } as unknown as undefined,
- setup(__props: { foo: string, bar?: number, baz: boolean, qux(): number }, { expose }) {
+ },
+ setup(__props: any, { expose }) {
expose()
-const props = __props
+const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number }
return { props }
`)
assertCode(content)
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (union)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: (${type}),`)
- expect(content).toMatch(
- `emits: ["foo", "bar", "baz"] as unknown as undefined`
- )
+ expect(content).toMatch(`emits: ["foo", "bar", "baz"]`)
})
test('defineEmits w/ type (interface)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (exported interface)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (type alias)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (exported type alias)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ({ (e: 'foo' | 'bar'): void }),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (referenced function type)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('defineEmits w/ type (referenced exported function type)', () => {
`)
assertCode(content)
expect(content).toMatch(`emit: ((e: 'foo' | 'bar') => void),`)
- expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
+ expect(content).toMatch(`emits: ["foo", "bar"]`)
})
test('runtime Enum', () => {
)})`
}
- return `\n props: ${propsDecls} as unknown as undefined,`
+ return `\n props: ${propsDecls},`
}
function genSetupPropsType(node: TSTypeLiteral | TSInterfaceBody) {
if (checkStaticDefaults()) {
// if withDefaults() is used, we need to remove the optional flags
// on props that have default values
- let res = `: { `
+ let res = `{ `
const members = node.type === 'TSTypeLiteral' ? node.members : node.body
for (const m of members) {
if (
}
return (res.length ? res.slice(0, -2) : res) + ` }`
} else {
- return `: ${scriptSetupSource.slice(node.start!, node.end!)}`
+ return scriptSetupSource.slice(node.start!, node.end!)
}
}
// 9. finalize setup() argument signature
let args = `__props`
if (propsTypeDecl) {
- args += genSetupPropsType(propsTypeDecl)
+ // mark as any and only cast on assignment
+ // since the user defined complex types may be incompatible with the
+ // inferred type from generated runtime declarations
+ args += `: any`
}
// inject user assignment of props
// we use a default __props so that template expressions referencing props
// can use it directly
if (propsIdentifier) {
- s.prependRight(startOffset, `\nconst ${propsIdentifier} = __props`)
+ s.prependRight(
+ startOffset,
+ `\nconst ${propsIdentifier} = __props${
+ propsTypeDecl ? ` as ${genSetupPropsType(propsTypeDecl)}` : ``
+ }`
+ )
}
// inject temp variables for async context preservation
if (hasAwait) {
- const any = isTS ? `:any` : ``
+ const any = isTS ? `: any` : ``
s.prependRight(startOffset, `\nlet __temp${any}, __restore${any}\n`)
}
return emits.size
? `\n emits: [${Array.from(emits)
.map(p => JSON.stringify(p))
- .join(', ')}] as unknown as undefined,`
+ .join(', ')}],`
: ``
}