|
| 1 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(5,5): error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor. |
| 2 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(20,6): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 3 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(21,6): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 4 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(22,13): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 5 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(28,6): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 6 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(34,15): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 7 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(68,10): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 8 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(69,10): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 9 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(70,10): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 10 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(75,15): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 11 | +tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 12 | + |
| 13 | + |
| 14 | +==== tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts (11 errors) ==== |
| 15 | + // Suppress strict property initialization check |
| 16 | + |
| 17 | + class C1 { |
| 18 | + a!: number; |
| 19 | + b: string; // Error |
| 20 | + ~ |
| 21 | +!!! error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor. |
| 22 | + } |
| 23 | + |
| 24 | + // Suppress definite assignment check in constructor |
| 25 | + |
| 26 | + class C2 { |
| 27 | + a!: number; |
| 28 | + constructor() { |
| 29 | + let x = this.a; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Definite assignment assertion requires type annotation, no initializer, no static modifier |
| 34 | + |
| 35 | + class C3 { |
| 36 | + a! = 1; |
| 37 | + ~ |
| 38 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 39 | + b!: number = 1; |
| 40 | + ~ |
| 41 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 42 | + static c!: number; |
| 43 | + ~ |
| 44 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 45 | + } |
| 46 | + |
| 47 | + // Definite assignment assertion not permitted in ambient context |
| 48 | + |
| 49 | + declare class C4 { |
| 50 | + a!: number; |
| 51 | + ~ |
| 52 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 53 | + } |
| 54 | + |
| 55 | + // Definite assignment assertion not permitted on abstract property |
| 56 | + |
| 57 | + abstract class C5 { |
| 58 | + abstract a!: number; |
| 59 | + ~ |
| 60 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 61 | + } |
| 62 | + |
| 63 | + // Suppress definite assignment check for variable |
| 64 | + |
| 65 | + function f1() { |
| 66 | + let x!: number; |
| 67 | + let y = x; |
| 68 | + var a!: number; |
| 69 | + var b = a; |
| 70 | + } |
| 71 | + |
| 72 | + function f2() { |
| 73 | + let x!: string | number; |
| 74 | + if (typeof x === "string") { |
| 75 | + let s: string = x; |
| 76 | + } |
| 77 | + else { |
| 78 | + let n: number = x; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + function f3() { |
| 83 | + let x!: number; |
| 84 | + const g = () => { |
| 85 | + x = 1; |
| 86 | + } |
| 87 | + g(); |
| 88 | + let y = x; |
| 89 | + } |
| 90 | + |
| 91 | + // Definite assignment assertion requires type annotation and no initializer |
| 92 | + |
| 93 | + function f4() { |
| 94 | + let a!; |
| 95 | + ~ |
| 96 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 97 | + let b! = 1; |
| 98 | + ~ |
| 99 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 100 | + let c!: number = 1; |
| 101 | + ~ |
| 102 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 103 | + } |
| 104 | + |
| 105 | + // Definite assignment assertion not permitted in ambient context |
| 106 | + |
| 107 | + declare let v1!: number; |
| 108 | + ~ |
| 109 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 110 | + declare var v2!: number; |
| 111 | + ~ |
| 112 | +!!! error TS1255: A definite assignment assertion '!' is not permitted in this context. |
| 113 | + |
0 commit comments