fix(sfc/types): allow use default factory for primitive types in withDefaults (#5939)
				
					
				
			fix #5938
This commit is contained in:
		
							parent
							
								
									dddbd96dfe
								
							
						
					
					
						commit
						b5462822d6
					
				@ -139,7 +139,7 @@ type InferDefault<P, T> = T extends
 | 
				
			|||||||
  | boolean
 | 
					  | boolean
 | 
				
			||||||
  | symbol
 | 
					  | symbol
 | 
				
			||||||
  | Function
 | 
					  | Function
 | 
				
			||||||
  ? T
 | 
					  ? T | ((props: P) => T)
 | 
				
			||||||
  : (props: P) => T
 | 
					  : (props: P) => T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PropsWithDefaults<Base, Defaults> = Base & {
 | 
					type PropsWithDefaults<Base, Defaults> = Base & {
 | 
				
			||||||
 | 
				
			|||||||
@ -28,12 +28,14 @@ describe('defineProps w/ type declaration + withDefaults', () => {
 | 
				
			|||||||
      obj?: { x: number }
 | 
					      obj?: { x: number }
 | 
				
			||||||
      fn?: (e: string) => void
 | 
					      fn?: (e: string) => void
 | 
				
			||||||
      x?: string
 | 
					      x?: string
 | 
				
			||||||
 | 
					      genStr?: string
 | 
				
			||||||
    }>(),
 | 
					    }>(),
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      number: 123,
 | 
					      number: 123,
 | 
				
			||||||
      arr: () => [],
 | 
					      arr: () => [],
 | 
				
			||||||
      obj: () => ({ x: 123 }),
 | 
					      obj: () => ({ x: 123 }),
 | 
				
			||||||
      fn: () => {}
 | 
					      fn: () => {},
 | 
				
			||||||
 | 
					      genStr: () => ''
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,6 +45,7 @@ describe('defineProps w/ type declaration + withDefaults', () => {
 | 
				
			|||||||
  res.fn('hi')
 | 
					  res.fn('hi')
 | 
				
			||||||
  // @ts-expect-error
 | 
					  // @ts-expect-error
 | 
				
			||||||
  res.x.slice()
 | 
					  res.x.slice()
 | 
				
			||||||
 | 
					  res.genStr.slice()
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('defineProps w/ union type declaration + withDefaults', () => {
 | 
					describe('defineProps w/ union type declaration + withDefaults', () => {
 | 
				
			||||||
@ -51,11 +54,13 @@ describe('defineProps w/ union type declaration + withDefaults', () => {
 | 
				
			|||||||
      union1?: number | number[] | { x: number }
 | 
					      union1?: number | number[] | { x: number }
 | 
				
			||||||
      union2?: number | number[] | { x: number }
 | 
					      union2?: number | number[] | { x: number }
 | 
				
			||||||
      union3?: number | number[] | { x: number }
 | 
					      union3?: number | number[] | { x: number }
 | 
				
			||||||
 | 
					      union4?: number | number[] | { x: number }
 | 
				
			||||||
    }>(),
 | 
					    }>(),
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      union1: 123,
 | 
					      union1: 123,
 | 
				
			||||||
      union2: () => [123],
 | 
					      union2: () => [123],
 | 
				
			||||||
      union3: () => ({ x: 123 })
 | 
					      union3: () => ({ x: 123 }),
 | 
				
			||||||
 | 
					      union4: () => 123,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user