mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
//// [tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts] ////
|
|
|
|
//// [thisInInvalidContexts.ts]
|
|
class BaseErrClass {
|
|
constructor(t: any) { }
|
|
}
|
|
|
|
class ClassWithNoInitializer extends BaseErrClass {
|
|
t;
|
|
//'this' in optional super call
|
|
constructor() {
|
|
super(this); // Error
|
|
}
|
|
}
|
|
|
|
class ClassWithInitializer extends BaseErrClass {
|
|
t = 4;
|
|
//'this' in required super call
|
|
constructor() {
|
|
super(this); // Error
|
|
}
|
|
}
|
|
|
|
namespace M {
|
|
//'this' in module variable
|
|
var x = this; // Error
|
|
}
|
|
|
|
//'this' as type parameter constraint
|
|
// function fn<T extends this >() { } // Error
|
|
|
|
//'this' as a type argument
|
|
function genericFunc<T>(x: T) { }
|
|
genericFunc<this>(undefined); // Should be an error
|
|
|
|
class ErrClass3 extends this {
|
|
|
|
}
|
|
|
|
//'this' as a computed enum value
|
|
enum SomeEnum {
|
|
A = this, // Should not be allowed
|
|
B = this.spaaaace // Also should not be allowed
|
|
}
|
|
|
|
|
|
|
|
//// [thisInInvalidContexts.js]
|
|
"use strict";
|
|
class BaseErrClass {
|
|
constructor(t) { }
|
|
}
|
|
class ClassWithNoInitializer extends BaseErrClass {
|
|
//'this' in optional super call
|
|
constructor() {
|
|
super(this); // Error
|
|
}
|
|
}
|
|
class ClassWithInitializer extends BaseErrClass {
|
|
//'this' in required super call
|
|
constructor() {
|
|
super(this); // Error
|
|
this.t = 4;
|
|
}
|
|
}
|
|
var M;
|
|
(function (M) {
|
|
//'this' in module variable
|
|
var x = this; // Error
|
|
})(M || (M = {}));
|
|
//'this' as type parameter constraint
|
|
// function fn<T extends this >() { } // Error
|
|
//'this' as a type argument
|
|
function genericFunc(x) { }
|
|
genericFunc(undefined); // Should be an error
|
|
class ErrClass3 extends this {
|
|
}
|
|
//'this' as a computed enum value
|
|
var SomeEnum;
|
|
(function (SomeEnum) {
|
|
SomeEnum[SomeEnum["A"] = this] = "A";
|
|
SomeEnum[SomeEnum["B"] = this.spaaaace] = "B"; // Also should not be allowed
|
|
})(SomeEnum || (SomeEnum = {}));
|