Correct some incorrectly-added declare in functions.

This commit is contained in:
Daniel Rosenwasser 2026-01-08 01:33:50 +00:00
parent 13ec6c8e4f
commit f89e69581e
8 changed files with 21 additions and 21 deletions

View File

@ -4,7 +4,7 @@ interface I1<T> {
}
function foo() {
declare var test: I1<string>;
var test!: I1<string>;
test("expects boolean instead of string"); // should not error - "test" should not expect a boolean
test(true); // should error - string expected
}

View File

@ -1,8 +1,8 @@
class Chain<T> {
constructor(public value: T) { }
then<S extends T>(cb: (x: T) => S): Chain<S> {
declare var t: T;
declare var s: S;
var t!: T;
var s!: S;
// Ok to go down the chain, but error to climb up the chain
(new Chain(t)).then(tt => s).then(ss => t);
@ -24,9 +24,9 @@ interface I {
class Chain2<T extends I> {
constructor(public value: T) { }
then<S extends T>(cb: (x: T) => S): Chain2<S> {
declare var i: I;
declare var t: T;
declare var s: S;
var i!: I;
var t!: T;
var s!: S;
// Ok to go down the chain, check the constraint at the end.
// Should get an error that we are assigning a string to a number
(new Chain2(i)).then(ii => t).then(tt => s).value.x = "";

View File

@ -7,6 +7,6 @@ declare class X { }
// @filename: b.ts
export {X};
export function f() {
declare var x: X;
var x!: X;
return x;
}

View File

@ -1,5 +1,5 @@
function f1<T>(args: T) {
declare var v1: { [index: string]: new (arg: T) => Date };
var v1!: { [index: string]: new (arg: T) => Date };
var v2 = v1['test'];
v2(args);
return new v2(args); // used to give error
@ -8,7 +8,7 @@ function f1<T>(args: T) {
interface I1<T> { new (arg: T): Date };
function f2<T>(args: T) {
declare var v1: { [index: string]: I1<T> };
var v1!: { [index: string]: I1<T> };
var v2 = v1['test'];
var y = v2(args);
return new v2(args); // used to give error

View File

@ -27,16 +27,16 @@ namespace Generics {
}
function foo<T extends Base>() {
declare var a: A<T>;
declare var b: { [x: number]: Derived; }
var a!: A<T>;
var b!: { [x: number]: Derived; }
a = b; // error
b = a; // error
declare var b2: { [x: number]: Derived2; }
var b2!: { [x: number]: Derived2; }
a = b2; // error
b2 = a; // error
declare var b3: { [x: number]: T; }
var b3!: { [x: number]: T; }
a = b3; // ok
b3 = a; // ok
}

View File

@ -28,12 +28,12 @@ namespace Generics {
}
function foo<T extends Derived>() {
declare var a: A<T>;
declare var b: { [x: number]: Derived; };
var a!: A<T>;
var b!: { [x: number]: Derived; };
a = b; // error
b = a; // ok
declare var b2: { [x: number]: T; };
var b2!: { [x: number]: T; };
a = b2; // ok
b2 = a; // ok
}

View File

@ -41,12 +41,12 @@ namespace Generics {
b2 = a1; // error
function foo<T extends Base>() {
declare var b3: { [x: string]: Derived; };
declare var a3: A<T>;
var b3!: { [x: string]: Derived; };
var a3!: A<T>;
a3 = b3; // error
b3 = a3; // error
declare var b4: { [x: string]: Derived2; };
var b4!: { [x: string]: Derived2; };
a3 = b4; // error
b4 = a3; // error
}

View File

@ -15,8 +15,8 @@ namespace Generics {
}
function foo<T extends Derived>() {
declare var a: A<T>;
declare var b: { [x: string]: string; };
var a!: A<T>;
var b!: { [x: string]: string; };
a = b; // error
b = a; // error
}