File: checkObjectDefineProperty.errors.txt

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (79 lines) | stat: -rw-r--r-- 2,843 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
tests/cases/conformance/jsdoc/validate.ts(14,3): error TS2540: Cannot assign to 'lastName' because it is a read-only property.
tests/cases/conformance/jsdoc/validate.ts(15,3): error TS2540: Cannot assign to 'houseNumber' because it is a read-only property.
tests/cases/conformance/jsdoc/validate.ts(16,1): error TS2322: Type '12' is not assignable to type 'string'.
tests/cases/conformance/jsdoc/validate.ts(17,3): error TS2540: Cannot assign to 'middleInit' because it is a read-only property.


==== tests/cases/conformance/jsdoc/validate.ts (4 errors) ====
    // Validate in TS as simple validations would usually be interpreted as more special assignments
    import x = require("./");
    x.name;
    x.middleInit;
    x.lastName;
    x.zip;
    x.houseNumber;
    x.zipStr;
    
    x.name = "Another";
    x.zip = 98123;
    x.zipStr = "OK";
    
    x.lastName = "should fail";
      ~~~~~~~~
!!! error TS2540: Cannot assign to 'lastName' because it is a read-only property.
    x.houseNumber = 12; // should also fail
      ~~~~~~~~~~~
!!! error TS2540: Cannot assign to 'houseNumber' because it is a read-only property.
    x.zipStr = 12; // should fail
    ~~~~~~~~
!!! error TS2322: Type '12' is not assignable to type 'string'.
    x.middleInit = "R"; // should also fail
      ~~~~~~~~~~
!!! error TS2540: Cannot assign to 'middleInit' because it is a read-only property.
    
==== tests/cases/conformance/jsdoc/index.js (0 errors) ====
    const x = {};
    Object.defineProperty(x, "name", { value: "Charles", writable: true });
    Object.defineProperty(x, "middleInit", { value: "H" });
    Object.defineProperty(x, "lastName", { value: "Smith", writable: false });
    Object.defineProperty(x, "zip", { get() { return 98122 }, set(_) { /*ignore*/ } });
    Object.defineProperty(x, "houseNumber", { get() { return 21.75 } });
    Object.defineProperty(x, "zipStr", {
        /** @param {string} str */
        set(str) {
            this.zip = Number(str) 
        }
    });
    
    /**
     * @param {{name: string}} named
     */
    function takeName(named) { return named.name; }
    
    takeName(x);
    /**
     * @type {number}
     */
    var a = x.zip;
    
    /**
     * @type {number}
     */
    var b = x.houseNumber;
    
    const returnExemplar = () => x;
    const needsExemplar = (_ = x) => void 0;
    
    const expected = /** @type {{name: string, readonly middleInit: string, readonly lastName: string, zip: number, readonly houseNumber: number, zipStr: string}} */(/** @type {*} */(null));
    
    /**
     * 
     * @param {typeof returnExemplar} a 
     * @param {typeof needsExemplar} b 
     */
    function match(a, b) {}
    
    match(() => expected, (x = expected) => void 0);
    
    module.exports = x;