Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74a866c

Browse filesBrowse files
committed
refactor: run prettier
1 parent 7c87b03 commit 74a866c
Copy full SHA for 74a866c

File tree

Expand file treeCollapse file tree

7 files changed

+128
-63
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+128
-63
lines changed

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"clean": "rimraf dist lib",
2020
"example": "webpack --config example/webpack.config.js",
2121
"dev": "webpack --config example/webpack.config.js --watch",
22-
"lint": "prettier --parser typescript \"**/*.[jt]s?(x)\"",
22+
"lint": "prettier -l --parser typescript \"**/*.[jt]s?(x)\"",
2323
"lint:fix": "yarn lint --write",
2424
"test": "yarn test:ts && yarn test:babel && yarn test:dts",
2525
"test:ts": "jest",

‎src/helpers.ts

Copy file name to clipboardExpand all lines: src/helpers.ts
+53-18Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
import { ComponentOptions, UnwrapRef, ComponentObjectPropsOptions, ExtractPropTypes } from 'vue'
2-
import { ClassComponentHooks, EmitsOptions, ObjectEmitsOptions, Vue, VueBase, VueConstructor, VueMixin } from './vue'
1+
import {
2+
ComponentOptions,
3+
UnwrapRef,
4+
ComponentObjectPropsOptions,
5+
ExtractPropTypes,
6+
} from 'vue'
7+
8+
import {
9+
ClassComponentHooks,
10+
EmitsOptions,
11+
ObjectEmitsOptions,
12+
Vue,
13+
VueBase,
14+
VueConstructor,
15+
VueMixin,
16+
} from './vue'
317

418
export function Options<V extends Vue>(
519
options: ComponentOptions & ThisType<V>
@@ -26,7 +40,9 @@ export function createDecorator(
2640
): VueDecorator {
2741
return (target: Vue | VueConstructor, key?: any, index?: any) => {
2842
const Ctor =
29-
typeof target === 'function' ? target : (target.constructor as VueConstructor)
43+
typeof target === 'function'
44+
? target
45+
: (target.constructor as VueConstructor)
3046
if (!Ctor.__vccDecorators) {
3147
Ctor.__vccDecorators = []
3248
}
@@ -45,23 +61,26 @@ export type UnionToIntersection<U> = (
4561

4662
export type ExtractInstance<T> = T extends VueMixin<infer V> ? V : never
4763

48-
export type NarrowEmit<T extends VueBase>
49-
= Omit<T, '$emit' | keyof ClassComponentHooks>
50-
64+
export type NarrowEmit<T extends VueBase> = Omit<
65+
T,
66+
'$emit' | keyof ClassComponentHooks
67+
>
5168
// Reassign class component hooks as mapped types makes prototype function (`mounted(): void`) instance function (`mounted: () => void`).
5269
& ClassComponentHooks
5370

5471
// Exclude generic $emit type (`$emit: (event: string, ...args: any[]) => void`) if there are another intersected type.
5572
& {
56-
$emit: T['$emit'] extends ((event: string, ...args: any[]) => void) & infer R
57-
? unknown extends R
58-
? T['$emit']
59-
: R
60-
: T['$emit']
73+
$emit: T['$emit'] extends (((event: string, ...args: any[]) => void) & infer R)
74+
? unknown extends R
75+
? T['$emit']
76+
: R
77+
: T['$emit']
6178
}
6279

6380
export type MixedVueBase<Mixins extends VueMixin[]> = Mixins extends (infer T)[]
64-
? VueConstructor<NarrowEmit<UnionToIntersection<ExtractInstance<T>> & Vue> & VueBase>
81+
? VueConstructor<
82+
NarrowEmit<UnionToIntersection<ExtractInstance<T>> & Vue> & VueBase
83+
>
6584
: never
6685

6786
export function mixins<T extends VueMixin[]>(...Ctors: T): MixedVueBase<T>
@@ -77,16 +96,26 @@ export function mixins(...Ctors: VueMixin[]): VueConstructor {
7796
Ctors.forEach((Ctor) => {
7897
const data = new (Ctor as VueConstructor)(...args)
7998
Object.keys(data).forEach((key) => {
80-
;(this as any)[key] = (data as any)[key]
99+
; (this as any)[key] = (data as any)[key]
81100
})
82101
})
83102
}
84103
}
85104
}
86105

87-
export function props<PropNames extends string, Props = Readonly<{ [key in PropNames]?: any }>>(propNames: PropNames[]): VueConstructor<Vue<Props> & Props>
88-
export function props<PropsOptions extends ComponentObjectPropsOptions, Props = Readonly<ExtractPropTypes<PropsOptions>>>(propsOptions: PropsOptions): VueConstructor<Vue<Props> & Props>
89-
export function props(propsOptions: string[] | ComponentObjectPropsOptions): VueConstructor {
106+
export function props<
107+
PropNames extends string,
108+
Props = Readonly<{ [key in PropNames]?: any }>
109+
>(propNames: PropNames[]): VueConstructor<Vue<Props> & Props>
110+
111+
export function props<
112+
PropsOptions extends ComponentObjectPropsOptions,
113+
Props = Readonly<ExtractPropTypes<PropsOptions>>
114+
>(propsOptions: PropsOptions): VueConstructor<Vue<Props> & Props>
115+
116+
export function props(
117+
propsOptions: string[] | ComponentObjectPropsOptions
118+
): VueConstructor {
90119
class PropsMixin extends Vue {
91120
static __vccExtend(options: ComponentOptions) {
92121
options.props = propsOptions
@@ -95,8 +124,14 @@ export function props(propsOptions: string[] | ComponentObjectPropsOptions): Vue
95124
return PropsMixin
96125
}
97126

98-
export function emits<EmitNames extends string>(emitNames: EmitNames[]): VueConstructor<Vue<unknown, EmitNames[]>>
99-
export function emits<EmitsOptions extends ObjectEmitsOptions>(emitsOptions: EmitsOptions): VueConstructor<Vue<unknown, EmitsOptions>>
127+
export function emits<EmitNames extends string>(
128+
emitNames: EmitNames[]
129+
): VueConstructor<Vue<unknown, EmitNames[]>>
130+
131+
export function emits<EmitsOptions extends ObjectEmitsOptions>(
132+
emitsOptions: EmitsOptions
133+
): VueConstructor<Vue<unknown, EmitsOptions>>
134+
100135
export function emits(emitsOptions: EmitsOptions): VueConstructor {
101136
class EmitsMixin extends Vue {
102137
static __vccExtend(options: ComponentOptions) {

‎src/index.ts

Copy file name to clipboardExpand all lines: src/index.ts
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@
44

55
export { Vue, ClassComponentHooks } from './vue'
66

7-
export { Options, createDecorator, mixins, props, emits, setup } from './helpers'
7+
export {
8+
Options,
9+
createDecorator,
10+
mixins,
11+
props,
12+
emits,
13+
setup,
14+
} from './helpers'
815

916
/**
1017
* Other types
1118
*/
1219

13-
export { VueBase, VueMixin, VueStatic, VueConstructor, EmitsOptions, ObjectEmitsOptions } from './vue'
20+
export {
21+
VueBase,
22+
VueMixin,
23+
VueStatic,
24+
VueConstructor,
25+
EmitsOptions,
26+
ObjectEmitsOptions,
27+
} from './vue'
1428

1529
export {
1630
VueDecorator,
1731
MixedVueBase,
1832
UnionToIntersection,
1933
ExtractInstance,
20-
NarrowEmit
34+
NarrowEmit,
2135
} from './helpers'

‎src/vue.ts

Copy file name to clipboardExpand all lines: src/vue.ts
+9-11Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface VueStatic {
5151
__vccDecorators?: ((options: ComponentOptions) => void)[]
5252

5353
/** @internal */
54-
__vccExtend: ((options: ComponentOptions) => void)
54+
__vccExtend: (options: ComponentOptions) => void
5555

5656
/** @internal */
5757
__vccHooks: string[]
@@ -107,18 +107,16 @@ export interface ClassComponentHooks {
107107
serverPrefetch?(): Promise<unknown>
108108
}
109109

110-
export type ObjectEmitsOptions = Record<string, ((...args: any[]) => any) | null>
110+
export type ObjectEmitsOptions = Record<
111+
string,
112+
((...args: any[]) => any) | null
113+
>
111114
export type EmitsOptions = ObjectEmitsOptions | string[]
112115

113-
export type Vue<Props = unknown, Emits extends EmitsOptions = {}> = ComponentPublicInstance<
114-
{},
115-
{},
116-
{},
117-
{},
118-
{},
119-
Emits,
120-
Props
121-
> &
116+
export type Vue<
117+
Props = unknown,
118+
Emits extends EmitsOptions = {}
119+
> = ComponentPublicInstance<{}, {}, {}, {}, {}, Emits, Props> &
122120
ClassComponentHooks
123121

124122
export interface VueConstructor<V extends VueBase = Vue> extends VueMixin<V> {

‎test-dts/helpers.d.ts

Copy file name to clipboardExpand all lines: test-dts/helpers.d.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ declare function it(name: string, fn: () => void): void
44
declare function equals<T, U>(value: Equals<T, U>): void
55

66
// https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
7-
type Equals<X, Y> =
8-
(<T>() => T extends X ? 1 : 2) extends
9-
(<T>() => T extends Y ? 1 : 2) ? true : false;
7+
type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y
8+
? 1
9+
: 2
10+
? true
11+
: false

‎test-dts/mixins.ts

Copy file name to clipboardExpand all lines: test-dts/mixins.ts
+28-20Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,33 @@ describe('mixins', () => {
2323
// @ts-expect-error
2424
this.nonExist
2525

26-
equals<typeof vm.$emit, ((event: string, ...args: any[]) => void) & ((event: never, ...args: any[]) => void)>(true)
26+
equals<
27+
typeof vm.$emit,
28+
((event: string, ...args: any[]) => void) &
29+
((event: never, ...args: any[]) => void)
30+
>(true)
2731
}
2832
}
2933
})
3034

3135
it('mixes props and emits mixins', () => {
3236
const Props = props({
33-
value: String
37+
value: String,
3438
})
3539

3640
const Emits = emits({
37-
input: (value: string) => true
41+
input: (value: string) => true,
3842
})
3943

4044
class App extends mixins(Props, Emits) {
4145
mounted() {
4246
const vm = this
4347
equals<typeof vm.$props.value, string | undefined>(true)
44-
equals<typeof vm.$emit, ((event: 'input', value: string) => void) & ((event: never, ...args: any[]) => void)>(true)
48+
equals<
49+
typeof vm.$emit,
50+
((event: 'input', value: string) => void) &
51+
((event: never, ...args: any[]) => void)
52+
>(true)
4553
}
4654
}
4755
})
@@ -68,27 +76,29 @@ describe('props', () => {
6876
const Props = props({
6977
foo: {
7078
type: Number,
71-
default: 42
79+
default: 42,
7280
},
7381

7482
bar: {
7583
type: String,
76-
required: true
84+
required: true,
7785
},
7886

7987
baz: {
80-
type: Boolean
81-
}
88+
type: Boolean,
89+
},
8290
})
8391

8492
class App extends Props {
8593
mounted() {
86-
type ExpectedProps = Readonly<{
87-
foo: number
88-
bar: string
89-
} & {
90-
baz?: boolean | undefined
91-
}>
94+
type ExpectedProps = Readonly<
95+
{
96+
foo: number
97+
bar: string
98+
} & {
99+
baz?: boolean | undefined
100+
}
101+
>
92102

93103
const vm = this
94104
equals<typeof vm.foo, number>(true)
@@ -128,15 +138,13 @@ describe('emits', () => {
128138
it('types with object style emits definition', () => {
129139
const Emits = emits({
130140
change: (value: number) => true,
131-
input: (value: number, additional: string) => true
141+
input: (value: number, additional: string) => true,
132142
})
133143

134144
class App extends Emits {
135145
mounted() {
136-
type ExpectedEmit
137-
= ((event: 'change', value: number) => void)
138-
& ((event: 'input', value: number, additional: string) => void)
139-
146+
type ExpectedEmit = ((event: 'change', value: number) => void) &
147+
((event: 'input', value: number, additional: string) => void)
140148

141149
const vm = this
142150
equals<typeof vm.$emit, ExpectedEmit>(true)
@@ -153,4 +161,4 @@ describe('emits', () => {
153161
}
154162
}
155163
})
156-
})
164+
})

‎test/specs/test.spec.ts

Copy file name to clipboardExpand all lines: test/specs/test.spec.ts
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import 'reflect-metadata'
22
import { h, resolveComponent, ref, onMounted, Ref, watch, toRef } from 'vue'
3-
import { Options, createDecorator, mixins, Vue, setup, props, emits } from '../../src'
3+
import {
4+
Options,
5+
createDecorator,
6+
mixins,
7+
Vue,
8+
setup,
9+
props,
10+
emits,
11+
} from '../../src'
412
import { mount, unmount } from '../helpers'
513

614
describe('vue-class-component', () => {
@@ -371,12 +379,12 @@ describe('vue-class-component', () => {
371379
const Props = props({
372380
foo: {
373381
type: String,
374-
default: 'The answer is'
382+
default: 'The answer is',
375383
},
376384
bar: {
377385
type: Number,
378-
required: true
379-
}
386+
required: true,
387+
},
380388
})
381389

382390
class App extends Props {
@@ -413,7 +421,7 @@ describe('vue-class-component', () => {
413421

414422
onBar: (res1: string, res2: string) => {
415423
this.barResult = res1 + res2
416-
}
424+
},
417425
})
418426
}
419427
}
@@ -426,7 +434,7 @@ describe('vue-class-component', () => {
426434
it('emits mixin: emits options object', () => {
427435
const Emits = emits({
428436
foo: (_n: number) => true,
429-
bar: (_n1: string, _n2: string) => true
437+
bar: (_n1: string, _n2: string) => true,
430438
})
431439

432440
class Child extends Emits {
@@ -452,7 +460,7 @@ describe('vue-class-component', () => {
452460

453461
onBar: (res1: string, res2: string) => {
454462
this.barResult = res1 + res2
455-
}
463+
},
456464
})
457465
}
458466
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.