@@ -20,6 +20,9 @@ import { type IsAny, type IsUnion, describe, expectType } from './utils'
2020describe ( 'with object props' , ( ) => {
2121 interface ExpectedProps {
2222 a ?: number | undefined
23+ aa : number
24+ aaa : number | null
25+ aaaa : number | undefined
2326 b : string
2427 e ?: Function
2528 h : boolean
@@ -53,6 +56,19 @@ describe('with object props', () => {
5356
5457 const props = {
5558 a : Number ,
59+ aa : {
60+ type : Number as PropType < number | undefined > ,
61+ default : 1 ,
62+ } ,
63+ aaa : {
64+ type : Number as PropType < number | null > ,
65+ default : 1 ,
66+ } ,
67+ aaaa : {
68+ type : Number as PropType < number | undefined > ,
69+ // `as const` prevents widening to `boolean` (keeps literal `true` type)
70+ required : true as const ,
71+ } ,
5672 // required should make property non-void
5773 b : {
5874 type : String ,
@@ -146,6 +162,13 @@ describe('with object props', () => {
146162 setup ( props ) {
147163 // type assertion. See https://github.com/SamVerschueren/tsd
148164 expectType < ExpectedProps [ 'a' ] > ( props . a )
165+ expectType < ExpectedProps [ 'aa' ] > ( props . aa )
166+ expectType < ExpectedProps [ 'aaa' ] > ( props . aaa )
167+
168+ // @ts -expect-error should included `undefined`
169+ expectType < number > ( props . aaaa )
170+ expectType < ExpectedProps [ 'aaaa' ] > ( props . aaaa )
171+
149172 expectType < ExpectedProps [ 'b' ] > ( props . b )
150173 expectType < ExpectedProps [ 'e' ] > ( props . e )
151174 expectType < ExpectedProps [ 'h' ] > ( props . h )
@@ -198,6 +221,8 @@ describe('with object props', () => {
198221 render ( ) {
199222 const props = this . $props
200223 expectType < ExpectedProps [ 'a' ] > ( props . a )
224+ expectType < ExpectedProps [ 'aa' ] > ( props . aa )
225+ expectType < ExpectedProps [ 'aaa' ] > ( props . aaa )
201226 expectType < ExpectedProps [ 'b' ] > ( props . b )
202227 expectType < ExpectedProps [ 'e' ] > ( props . e )
203228 expectType < ExpectedProps [ 'h' ] > ( props . h )
@@ -225,6 +250,8 @@ describe('with object props', () => {
225250
226251 // should also expose declared props on `this`
227252 expectType < ExpectedProps [ 'a' ] > ( this . a )
253+ expectType < ExpectedProps [ 'aa' ] > ( this . aa )
254+ expectType < ExpectedProps [ 'aaa' ] > ( this . aaa )
228255 expectType < ExpectedProps [ 'b' ] > ( this . b )
229256 expectType < ExpectedProps [ 'e' ] > ( this . e )
230257 expectType < ExpectedProps [ 'h' ] > ( this . h )
@@ -269,6 +296,7 @@ describe('with object props', () => {
269296 expectType < JSX . Element > (
270297 < MyComponent
271298 a = { 1 }
299+ aaaa = { 1 }
272300 b = "b"
273301 bb = "bb"
274302 e = { ( ) => { } }
@@ -295,6 +323,7 @@ describe('with object props', () => {
295323
296324 expectType < Component > (
297325 < MyComponent
326+ aaaa = { 1 }
298327 b = "b"
299328 dd = { { n : 1 } }
300329 ddd = { [ 'ddd' ] }
0 commit comments