TypeScript/tests/baselines/reference/typeofThis.errors.txt

170 lines
5.5 KiB
Plaintext

tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(24,19): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(32,19): error TS2532: Object is possibly 'undefined'.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(46,23): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(46,23): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(52,23): error TS2331: 'this' cannot be referenced in a module or namespace body.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(52,23): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(57,19): error TS7041: The containing arrow function captures the global value of 'this'.
tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts(57,24): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
==== tests/cases/conformance/types/specifyingTypes/typeQueries/typeofThis.ts (8 errors) ====
class Test {
data = {};
constructor() {
var copy: typeof this.data = {};
}
}
class Test1 {
data = { foo: '' };
['this'] = '';
constructor() {
var copy: typeof this.data = { foo: '' };
var foo: typeof this.data.foo = '';
var self: typeof this = this;
self.data;
var str: typeof this.this = '';
}
}
function Test2() {
let x: typeof this.no = 1;
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}
function Test3(this: { no: number }) {
let x: typeof this.no = 1;
}
function Test4(this: { no: number } | undefined) {
let x: typeof this.no = 1;
~~~~
!!! error TS2532: Object is possibly 'undefined'.
}
class Test5 {
no = 1;
f = () => {
// should not capture this.
let x: typeof this.no = 1;
}
}
namespace Test6 {
export let f = () => {
let x: typeof this.no = 1;
~~~~
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}
}
module Test7 {
export let f = () => {
let x: typeof this.no = 1;
~~~~
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
~~~~
!!! error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
}
}
const Test8 = () => {
let x: typeof this.no = 1;
~~~~
!!! error TS7041: The containing arrow function captures the global value of 'this'.
~~
!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
}
class Test9 {
no = 0;
this = 0;
f() {
if (this instanceof Test9D1) {
const d1: typeof this = this;
d1.f1();
}
if (this instanceof Test9D2) {
const d2: typeof this = this;
d2.f2();
}
}
g() {
if (this.no === 1) {
const no: typeof this.no = this.no;
}
if (this.this === 1) {
const no: typeof this.this = this.this;
}
}
}
class Test9D1 {
f1() {}
}
class Test9D2 {
f2() {}
}
class Test10 {
a?: { b?: string }
foo() {
let a: typeof this.a = undefined as any;
if (this.a) {
let a: typeof this.a = undefined as any; // should narrow to { b?: string }
let b: typeof this.a.b = undefined as any;
if (this.a.b) {
let b: typeof this.a.b = undefined as any; // should narrow to string
}
}
}
}
class Test11 {
this?: { x?: string };
foo() {
const o = this;
let bar: typeof o.this = {};
if (o.this && o.this.x) {
let y: string = o.this.x; // should narrow to string
}
}
}
class Tests12 {
test1() { // OK
type Test = typeof this;
}
test2() { // OK
for (;;) {}
type Test = typeof this;
}
test3() { // expected no compile errors
for (const dummy in []) {}
type Test = typeof this;
}
test4() { // expected no compile errors
for (const dummy of []) {}
type Test = typeof this;
}
}