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

Sign up
Appearance settings

Commit f6c205f

Browse files
fix: required default value = false
1 parent 6cb7153 commit f6c205f

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

‎lib/rules/define-props-declaration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function optionGetRequired(node) {
134134
if (node.type === 'ObjectExpression') {
135135
const requiredProperty = utils.findProperty(node, 'required')
136136
if (requiredProperty == null) {
137-
return undefined
137+
return false
138138
}
139139

140140
if (requiredProperty.value.type === 'Literal') {
@@ -143,7 +143,7 @@ function optionGetRequired(node) {
143143
}
144144

145145
// Unknown
146-
return undefined
146+
return false
147147
}
148148

149149
/**

‎tests/lib/rules/define-props-declaration.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ tester.run('define-props-declaration', rule, {
123123
`,
124124
output: `
125125
<script setup lang="ts">
126-
const props = defineProps<{ kind: string }>()
126+
const props = defineProps<{ kind?: string }>()
127127
</script>
128128
`,
129129
errors: [
@@ -146,7 +146,7 @@ tester.run('define-props-declaration', rule, {
146146
`,
147147
output: `
148148
<script setup lang="ts">
149-
const props = defineProps<{ kind: string }>()
149+
const props = defineProps<{ kind?: string }>()
150150
</script>
151151
`,
152152
errors: [
@@ -168,7 +168,7 @@ tester.run('define-props-declaration', rule, {
168168
`,
169169
output: `
170170
<script setup lang="ts">
171-
const props = defineProps<{ kind: string }>()
171+
const props = defineProps<{ kind?: string }>()
172172
</script>
173173
`,
174174
options: ['type-based'],
@@ -191,7 +191,7 @@ tester.run('define-props-declaration', rule, {
191191
`,
192192
output: `
193193
<script setup lang="ts">
194-
const props = defineProps<{ kind: number }>()
194+
const props = defineProps<{ kind?: number }>()
195195
</script>
196196
`,
197197
errors: [
@@ -207,13 +207,13 @@ tester.run('define-props-declaration', rule, {
207207
code: `
208208
<script setup lang="ts">
209209
const props = defineProps({
210-
kind: { type:Boolean}
210+
kind: { type:Boolean}
211211
})
212212
</script>
213213
`,
214214
output: `
215215
<script setup lang="ts">
216-
const props = defineProps<{ kind: boolean }>()
216+
const props = defineProps<{ kind?: boolean }>()
217217
</script>
218218
`,
219219
errors: [
@@ -235,7 +235,7 @@ tester.run('define-props-declaration', rule, {
235235
`,
236236
output: `
237237
<script setup lang="ts">
238-
const props = defineProps<{ kind: Record<string, any> }>()
238+
const props = defineProps<{ kind?: Record<string, any> }>()
239239
</script>
240240
`,
241241
errors: [
@@ -257,7 +257,7 @@ tester.run('define-props-declaration', rule, {
257257
`,
258258
output: `
259259
<script setup lang="ts">
260-
const props = defineProps<{ kind: any[] }>()
260+
const props = defineProps<{ kind?: any[] }>()
261261
</script>
262262
`,
263263
errors: [
@@ -279,7 +279,7 @@ tester.run('define-props-declaration', rule, {
279279
`,
280280
output: `
281281
<script setup lang="ts">
282-
const props = defineProps<{ kind: (...args: any[]) => any }>()
282+
const props = defineProps<{ kind?: (...args: any[]) => any }>()
283283
</script>
284284
`,
285285
errors: [
@@ -301,7 +301,7 @@ tester.run('define-props-declaration', rule, {
301301
`,
302302
output: `
303303
<script setup lang="ts">
304-
const props = defineProps<{ kind: User }>()
304+
const props = defineProps<{ kind?: User }>()
305305
</script>
306306
`,
307307
errors: [
@@ -325,7 +325,7 @@ tester.run('define-props-declaration', rule, {
325325
`,
326326
output: `
327327
<script setup lang="ts">
328-
const props = defineProps<{ kind: 'a' | 'b' }>()
328+
const props = defineProps<{ kind?: 'a' | 'b' }>()
329329
</script>
330330
`,
331331
errors: [
@@ -349,7 +349,7 @@ tester.run('define-props-declaration', rule, {
349349
`,
350350
output: `
351351
<script setup lang="ts">
352-
const props = defineProps<{ kind: { id: number; name: string } }>()
352+
const props = defineProps<{ kind?: { id: number; name: string } }>()
353353
</script>
354354
`,
355355
errors: [
@@ -377,7 +377,7 @@ tester.run('define-props-declaration', rule, {
377377
<script setup lang="ts">
378378
interface Kind { id: number; name: string }
379379
380-
const props = defineProps<{ kind: Kind }>()
380+
const props = defineProps<{ kind?: Kind }>()
381381
</script>
382382
`,
383383
errors: [
@@ -405,7 +405,7 @@ tester.run('define-props-declaration', rule, {
405405
<script setup lang="ts">
406406
import Kind from 'test'
407407
408-
const props = defineProps<{ kind: Kind }>()
408+
const props = defineProps<{ kind?: Kind }>()
409409
</script>
410410
`,
411411
errors: [
@@ -429,7 +429,7 @@ tester.run('define-props-declaration', rule, {
429429
`,
430430
output: `
431431
<script setup lang="ts">
432-
const props = defineProps<{ kind: string[] }>()
432+
const props = defineProps<{ kind?: string[] }>()
433433
</script>
434434
`,
435435
errors: [
@@ -447,14 +447,13 @@ tester.run('define-props-declaration', rule, {
447447
const props = defineProps({
448448
kind: {
449449
type: Function as PropType<(a: number, b: string) => boolean>,
450-
required: true
451450
}
452451
})
453452
</script>
454453
`,
455454
output: `
456455
<script setup lang="ts">
457-
const props = defineProps<{ kind: (a: number, b: string) => boolean }>()
456+
const props = defineProps<{ kind?: (a: number, b: string) => boolean }>()
458457
</script>
459458
`,
460459
errors: [
@@ -553,7 +552,7 @@ tester.run('define-props-declaration', rule, {
553552
`,
554553
output: `
555554
<script setup lang="ts">
556-
interface Props { kind: { id: number, name: string } }; const props = defineProps<Props>()
555+
interface Props { kind?: { id: number, name: string } }; const props = defineProps<Props>()
557556
</script>
558557
`,
559558
options: ['type-based', { separateInterface: true }],
@@ -578,7 +577,7 @@ tester.run('define-props-declaration', rule, {
578577
`,
579578
output: `
580579
<script setup lang="ts">
581-
const props = defineProps<{ kind: string | number }>()
580+
const props = defineProps<{ kind?: string | number }>()
582581
</script>
583582
`,
584583
errors: [
@@ -602,7 +601,7 @@ tester.run('define-props-declaration', rule, {
602601
`,
603602
output: `
604603
<script setup lang="ts">
605-
const props = defineProps<{ kind: number | string }>()
604+
const props = defineProps<{ kind?: number | string }>()
606605
</script>
607606
`,
608607
errors: [
@@ -626,7 +625,7 @@ tester.run('define-props-declaration', rule, {
626625
`,
627626
output: `
628627
<script setup lang="ts">
629-
const props = defineProps<{ kind: typeof Test }>()
628+
const props = defineProps<{ kind?: typeof Test }>()
630629
</script>
631630
`,
632631
errors: [

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /