File: nonObjectUnionNestedExcessPropertyCheck.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (38 lines) | stat: -rw-r--r-- 2,597 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(13,35): error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
  Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(16,49): error TS2322: Type '{ asdfasdf: string; }' is not assignable to type '{ testBool?: boolean; }'.
  Object literal may only specify known properties, and 'asdfasdf' does not exist in type '{ testBool?: boolean; }'.
tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts(19,56): error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
  Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.


==== tests/cases/compiler/nonObjectUnionNestedExcessPropertyCheck.ts (3 errors) ====
    interface IProps {
        iconProp?: string;
        nestedProp?: {
            testBool?: boolean;
        }
    }
    
    interface INestedProps {
        nestedProps?: IProps;
    }
    
    // These are the types of errors we want:
    const propB1: IProps | number = { INVALID_PROP_NAME: 'share', iconProp: 'test' };
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'number | IProps'.
!!! error TS2322:   Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.
    
    // Nested typing works here and we also get an expected error:
    const propB2: IProps | number = { nestedProp: { asdfasdf: 'test' }, iconProp: 'test' };
                                                    ~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ asdfasdf: string; }' is not assignable to type '{ testBool?: boolean; }'.
!!! error TS2322:   Object literal may only specify known properties, and 'asdfasdf' does not exist in type '{ testBool?: boolean; }'.
    
    // Want an error generated here but there isn't one.
    const propA1: INestedProps | number = { nestedProps: { INVALID_PROP_NAME: 'share', iconProp: 'test' } };
                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ INVALID_PROP_NAME: string; iconProp: string; }' is not assignable to type 'IProps'.
!!! error TS2322:   Object literal may only specify known properties, and 'INVALID_PROP_NAME' does not exist in type 'IProps'.