Skip to content

Commit ec10615

Browse files
committed
refactor: use ts definitions for defineProps
1 parent 5318edc commit ec10615

15 files changed

+129
-189
lines changed

app/components/DragonPortrait.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@
2424
</template>
2525

2626
<script setup lang="ts">
27-
import type { PropType } from 'vue';
2827
import type { PortraitData } from '../shared/types';
2928
30-
defineProps({
31-
data: {
32-
type: Object as PropType<PortraitData>,
33-
required: true,
29+
withDefaults(
30+
defineProps<{
31+
data: PortraitData;
32+
gen?: number;
33+
}>(),
34+
{
35+
gen: 1,
3436
},
35-
gen: {
36-
type: Number,
37-
required: false,
38-
default: 1,
39-
},
40-
});
37+
);
4138
/*,
4239
computed:{
4340
// determines whether to provide a full size image or a small image

app/components/DragonProblem.vue

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,21 @@
2525
</template>
2626

2727
<script setup lang="ts">
28-
import type { PropType } from 'vue';
2928
import type { MaybePartialLineageWithMetadata } from '../shared/types';
3029
import { hasParents } from '../shared/utils.js';
3130
import { Lineage } from '../shared/lineageHandler';
3231
33-
defineProps({
34-
dragon: {
35-
type: Object as PropType<MaybePartialLineageWithMetadata>,
36-
required: true,
32+
withDefaults(
33+
defineProps<{
34+
dragon: MaybePartialLineageWithMetadata;
35+
highlight?: string;
36+
error?: string;
37+
}>(),
38+
{
39+
highlight: '',
40+
error: '',
3741
},
38-
39-
highlight: {
40-
type: String,
41-
required: false,
42-
default: '',
43-
},
44-
45-
error: {
46-
type: String,
47-
required: false,
48-
default: '',
49-
},
50-
});
42+
);
5143
</script>
5244
<style scoped>
5345
.dragon-formatting-block {

app/components/FeedbackPanel.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
</template>
3333
<script setup lang="ts">
3434
import { onBeforeUnmount, ref } from 'vue';
35-
import type { PropType } from 'vue';
3635
3736
const Feedbacks = {
3837
none: 'none',
@@ -53,13 +52,14 @@ interface Properties {
5352
5453
type Feedback = Partial<Properties>;
5554
56-
const props = defineProps({
57-
globalSettings: {
58-
type: Object as PropType<Feedback>,
59-
required: false,
60-
default: () => {},
55+
const props = withDefaults(
56+
defineProps<{
57+
globalSettings?: Feedback;
58+
}>(),
59+
{
60+
globalSettings: () => ({}),
6161
},
62-
});
62+
);
6363
6464
defineEmits<{
6565
(e: 'closed'): void;

app/components/GhostBreedUpload.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ import settings from '../shared/settings.js';
2727
import DragonPortrait from './DragonPortrait.vue';
2828
import { placeholder } from '../shared/breeds.js';
2929
30-
const props = defineProps({
31-
label: {
32-
type: String,
33-
required: true,
30+
const props = withDefaults(
31+
defineProps<{
32+
label: string;
33+
disabled?: boolean;
34+
}>(),
35+
{
36+
disabled: false,
3437
},
35-
disabled: {
36-
type: Boolean,
37-
default: false,
38-
},
39-
});
38+
);
4039
4140
const emit = defineEmits<{
4241
(e: 'tileChosen', base64Data: string): void;

app/components/InputTextbox.vue

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
</template>
7171
<script setup lang="ts">
7272
import { ref, computed } from 'vue';
73-
import type { PropType } from 'vue';
7473
import { useDebounceFn, useShare } from '@vueuse/core';
7574
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
7675
@@ -81,40 +80,30 @@ const emit = defineEmits<{
8180
(e: 'copyFail'): void;
8281
}>();
8382
84-
const props = defineProps({
85-
type: {
86-
type: String as PropType<'input' | 'textarea'>,
87-
default: 'input',
88-
},
89-
tooltipTimeout: {
90-
type: Number,
91-
default: 2000,
92-
},
93-
showCopyButton: {
94-
type: Boolean,
95-
default: false,
96-
},
97-
showShareButton: {
98-
type: Boolean,
99-
default: false,
100-
},
101-
shareParams: {
102-
type: Object as PropType<{
83+
const props = withDefaults(
84+
defineProps<{
85+
type?: 'input' | 'textarea';
86+
tooltipTimeout?: number;
87+
showCopyButton?: boolean;
88+
showShareButton?: boolean;
89+
shareParams?: {
10390
title?: string;
10491
text?: string;
10592
buttonTitle?: string;
106-
}>,
107-
default: () => ({}),
108-
},
109-
copyButtonTitle: {
110-
type: String,
111-
default: 'Copy text',
112-
},
113-
selectAllOnFocus: {
114-
type: Boolean,
115-
default: false,
93+
};
94+
copyButtonTitle?: string;
95+
selectAllOnFocus?: boolean;
96+
}>(),
97+
{
98+
type: 'input',
99+
tooltipTimeout: 2000,
100+
showCopyButton: false,
101+
showShareButton: false,
102+
shareParams: () => ({}),
103+
copyButtonTitle: 'Copy text',
104+
selectAllOnFocus: false,
116105
},
117-
});
106+
);
118107
119108
const model = defineModel<string>({ required: true, default: '' });
120109

app/components/LineageBuilderToolbar.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@
214214

215215
<script setup lang="ts">
216216
import { computed, reactive, ref } from 'vue';
217-
import type { PropType } from 'vue';
218217
import { useResizeObserver } from '@vueuse/core';
219218
import type {
220219
BreedEntry,
@@ -393,16 +392,10 @@ const dialogs = reactive({
393392
showGenerateDialog: false,
394393
});
395394
396-
defineProps({
397-
config: {
398-
type: Object as PropType<LineageConfig>,
399-
required: true,
400-
},
401-
tree: {
402-
type: Object as PropType<PartialLineage>,
403-
required: true,
404-
},
405-
});
395+
defineProps<{
396+
config: LineageConfig;
397+
tree: PartialLineage;
398+
}>();
406399
407400
const emit = defineEmits<{
408401
(e: 'addParents'): void;

app/components/LineageView.vue

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
</template>
1919

2020
<script setup lang="ts">
21-
import type { PropType } from 'vue';
2221
import type {
2322
LineageConfig,
2423
PartialLineageWithMetadata,
@@ -28,22 +27,20 @@ import LineageViewNode from './LineageViewNode.vue';
2827
import { Lineage } from '../shared/lineageHandler';
2928
import LineageWrapper from './LineageWrapper.vue';
3029
31-
const props = defineProps({
32-
root: {
33-
type: Object as PropType<PartialLineageWithMetadata> | null,
34-
required: true,
35-
default: null,
36-
},
37-
config: {
38-
type: Object as PropType<LineageConfig>,
39-
required: false,
40-
default: () => ({
30+
const props = withDefaults(
31+
defineProps<{
32+
root?: PartialLineageWithMetadata | null;
33+
config?: LineageConfig;
34+
}>(),
35+
{
36+
root: null,
37+
config: () => ({
4138
showLabels: true,
4239
showInterface: false,
4340
disabled: true,
4441
}),
4542
},
46-
});
43+
);
4744
4845
const generations = computed(() =>
4946
props.root ? Lineage(props.root).generations() : 0,

app/components/LineageViewGenerationCounter.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
<script setup lang="ts">
1313
import { computed } from 'vue';
1414
15-
const props = defineProps({
16-
count: {
17-
type: Number,
18-
default: 1,
15+
const props = withDefaults(
16+
defineProps<{
17+
count?: number;
18+
/**
19+
* when set to -1, the lineage will not be cut off at any gen.
20+
*/
21+
limit?: number;
22+
}>(),
23+
{
24+
count: 1,
25+
limit: -1,
1926
},
20-
// when set to 1, the lineage will not be cut off at any gen
21-
limit: {
22-
type: Number,
23-
default: -1,
24-
},
25-
});
27+
);
2628
2729
const gens = computed<number[]>(() => {
2830
let length: number;

app/components/LineageViewNode.vue

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
<script setup lang="ts">
121121
/* eslint-disable vue/no-mutating-props */
122122
import { computed } from 'vue';
123-
import type { PropType } from 'vue';
124123
import type {
125124
BreedEntry,
126125
PartialLineageWithMetadata,
@@ -143,24 +142,16 @@ import { placeholder } from '../shared/breeds.js';
143142
import vOnLongPress from '../directives/long-press/vue-3-long-press';
144143
import useBreedSelector from '../composables/useBreedSelector';
145144
146-
const props = defineProps({
147-
// Dragon properties
148-
data: {
149-
type: Object as PropType<PartialLineageWithMetadata>,
150-
required: true,
145+
const props = withDefaults(
146+
defineProps<{
147+
data: PartialLineageWithMetadata;
148+
disabled?: boolean;
149+
nodesFromRoot: number;
150+
}>(),
151+
{
152+
disabled: true,
151153
},
152-
// Whether to disable the click
153-
disabled: {
154-
type: Boolean,
155-
default: true,
156-
required: false,
157-
},
158-
// How many gens is this?
159-
nodesFromRoot: {
160-
type: Number,
161-
required: true,
162-
},
163-
});
154+
);
164155
165156
const ls = localStorage;
166157
const appStore = useAppStore();

app/components/LineageViewNodeButton.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@
1515
<script setup lang="ts">
1616
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
1717
18-
defineProps({
19-
title: {
20-
type: String,
21-
required: true,
22-
},
23-
icon: {
24-
type: String,
25-
required: true,
26-
},
27-
});
18+
defineProps<{
19+
title: string;
20+
icon: string;
21+
}>();
22+
2823
const emit = defineEmits<{
2924
(e: 'click'): void;
3025
}>();

0 commit comments

Comments
 (0)