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
|
tests/cases/conformance/types/localTypes/localTypes4.ts(11,19): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(11,23): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(19,16): error TS2300: Duplicate identifier 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(20,19): error TS2300: Duplicate identifier 'T'.
==== tests/cases/conformance/types/localTypes/localTypes4.ts (4 errors) ====
function f1() {
// Type parameters are in scope in parameters and return types
function f<T>(x: T): T {
return undefined;
}
}
function f2() {
// Local types are not in scope in parameters and return types
function f(x: T): T {
~
!!! error TS2304: Cannot find name 'T'.
~
!!! error TS2304: Cannot find name 'T'.
interface T { }
return undefined;
}
}
function f3() {
// Type parameters and top-level local types are in same declaration space
function f<T>() {
~
!!! error TS2300: Duplicate identifier 'T'.
interface T { }
~
!!! error TS2300: Duplicate identifier 'T'.
return undefined;
}
}
function f4() {
// Local types are block scoped
interface T { x: number }
let v: T;
v.x = 10;
if (true) {
interface T { x: string }
let v: T;
v.x = "hello";
}
else {
v.x = 20;
}
}
|