Skip to content

Added test for contextually typing parameters in super calls. #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions tests/baselines/reference/superCallParameterContextualTyping3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//// [superCallParameterContextualTyping3.ts]
interface ContextualType<T> {
method(parameter: T): void;
}

class CBase<T> {
constructor(param: ContextualType<T>) {
}

foo(param: ContextualType<T>) {
}
}

class C extends CBase<string> {
constructor() {
// Should be okay.
// 'p' should have type 'string'.
super({
method(p) {
p.length;
}
});

// Should be okay.
// 'p' should have type 'string'.
super.foo({
method(p) {
p.length;
}
});
}
}

//// [superCallParameterContextualTyping3.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var CBase = (function () {
function CBase(param) {
}
CBase.prototype.foo = function (param) {
};
return CBase;
})();
var C = (function (_super) {
__extends(C, _super);
function C() {
// Should be okay.
// 'p' should have type 'string'.
_super.call(this, {
method: function (p) {
p.length;
}
});
// Should be okay.
// 'p' should have type 'string'.
_super.prototype.foo.call(this, {
method: function (p) {
p.length;
}
});
}
return C;
})(CBase);
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
=== tests/cases/conformance/expressions/contextualTyping/superCallParameterContextualTyping3.ts ===
interface ContextualType<T> {
>ContextualType : ContextualType<T>
>T : T

method(parameter: T): void;
>method : (parameter: T) => void
>parameter : T
>T : T
}

class CBase<T> {
>CBase : CBase<T>
>T : T

constructor(param: ContextualType<T>) {
>param : ContextualType<T>
>ContextualType : ContextualType<T>
>T : T
}

foo(param: ContextualType<T>) {
>foo : (param: ContextualType<T>) => void
>param : ContextualType<T>
>ContextualType : ContextualType<T>
>T : T
}
}

class C extends CBase<string> {
>C : C
>CBase : CBase<T>

constructor() {
// Should be okay.
// 'p' should have type 'string'.
super({
>super({ method(p) { p.length; } }) : void
>super : typeof CBase
>{ method(p) { p.length; } } : { method(p: string): void; }

method(p) {
>method : (p: string) => void
>p : string

p.length;
>p.length : number
>p : string
>length : number
}
});

// Should be okay.
// 'p' should have type 'string'.
super.foo({
>super.foo({ method(p) { p.length; } }) : void
>super.foo : (param: ContextualType<string>) => void
>super : CBase<string>
>foo : (param: ContextualType<string>) => void
>{ method(p) { p.length; } } : { method(p: string): void; }

method(p) {
>method : (p: string) => void
>p : string

p.length;
>p.length : number
>p : string
>length : number
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface ContextualType<T> {
method(parameter: T): void;
}

class CBase<T> {
constructor(param: ContextualType<T>) {
}

foo(param: ContextualType<T>) {
}
}

class C extends CBase<string> {
constructor() {
// Should be okay.
// 'p' should have type 'string'.
super({
method(p) {
p.length;
}
});

// Should be okay.
// 'p' should have type 'string'.
super.foo({
method(p) {
p.length;
}
});
}
}