-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Relax the constraints of isValidBaseType to allow base types to be constructor types #33146
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
weswigham
merged 5 commits into
microsoft:master
from
weswigham:relax-is-valid-base-type
Sep 23, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07283de
Relax the constraints of isValidBaseType to allow base types to be co…
weswigham a7df26b
Merge branch 'master' into relax-is-valid-base-type
weswigham 2bd78f1
Fix nit
weswigham 9edb28c
Reduce confusion between isConstructorType and isValidBaseType
weswigham fd6472c
Update comment
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
tests/baselines/reference/mixinIntersectionIsValidbaseType.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//// [mixinIntersectionIsValidbaseType.ts] | ||
export type Constructor<T extends object = object> = new (...args: any[]) => T; | ||
|
||
export interface Initable { | ||
init(...args: any[]): void; | ||
} | ||
|
||
/** | ||
* Plain mixin where the superclass must be Initable | ||
*/ | ||
export const Serializable = <K extends Constructor<Initable> & Initable>( | ||
SuperClass: K | ||
) => { | ||
const LocalMixin = (InnerSuperClass: K) => { | ||
return class SerializableLocal extends InnerSuperClass { | ||
} | ||
}; | ||
let ResultClass = LocalMixin(SuperClass); | ||
return ResultClass; | ||
}; | ||
|
||
const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => { | ||
let SomeHowOkay = class A extends SuperClass { | ||
}; | ||
|
||
let SomeHowNotOkay = class A extends Serializable(SuperClass) { | ||
}; | ||
}; | ||
|
||
//// [mixinIntersectionIsValidbaseType.js] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
/** | ||
* Plain mixin where the superclass must be Initable | ||
*/ | ||
exports.Serializable = function (SuperClass) { | ||
var LocalMixin = function (InnerSuperClass) { | ||
return /** @class */ (function (_super) { | ||
__extends(SerializableLocal, _super); | ||
function SerializableLocal() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return SerializableLocal; | ||
}(InnerSuperClass)); | ||
}; | ||
var ResultClass = LocalMixin(SuperClass); | ||
return ResultClass; | ||
}; | ||
var AMixin = function (SuperClass) { | ||
var SomeHowOkay = /** @class */ (function (_super) { | ||
__extends(A, _super); | ||
function A() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return A; | ||
}(SuperClass)); | ||
var SomeHowNotOkay = /** @class */ (function (_super) { | ||
__extends(A, _super); | ||
function A() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return A; | ||
}(exports.Serializable(SuperClass))); | ||
}; |
74 changes: 74 additions & 0 deletions
74
tests/baselines/reference/mixinIntersectionIsValidbaseType.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
=== tests/cases/compiler/mixinIntersectionIsValidbaseType.ts === | ||
export type Constructor<T extends object = object> = new (...args: any[]) => T; | ||
>Constructor : Symbol(Constructor, Decl(mixinIntersectionIsValidbaseType.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mixinIntersectionIsValidbaseType.ts, 0, 24)) | ||
>args : Symbol(args, Decl(mixinIntersectionIsValidbaseType.ts, 0, 58)) | ||
>T : Symbol(T, Decl(mixinIntersectionIsValidbaseType.ts, 0, 24)) | ||
|
||
export interface Initable { | ||
>Initable : Symbol(Initable, Decl(mixinIntersectionIsValidbaseType.ts, 0, 79)) | ||
|
||
init(...args: any[]): void; | ||
>init : Symbol(Initable.init, Decl(mixinIntersectionIsValidbaseType.ts, 2, 27)) | ||
>args : Symbol(args, Decl(mixinIntersectionIsValidbaseType.ts, 3, 9)) | ||
} | ||
|
||
/** | ||
* Plain mixin where the superclass must be Initable | ||
*/ | ||
export const Serializable = <K extends Constructor<Initable> & Initable>( | ||
>Serializable : Symbol(Serializable, Decl(mixinIntersectionIsValidbaseType.ts, 9, 12)) | ||
>K : Symbol(K, Decl(mixinIntersectionIsValidbaseType.ts, 9, 29)) | ||
>Constructor : Symbol(Constructor, Decl(mixinIntersectionIsValidbaseType.ts, 0, 0)) | ||
>Initable : Symbol(Initable, Decl(mixinIntersectionIsValidbaseType.ts, 0, 79)) | ||
>Initable : Symbol(Initable, Decl(mixinIntersectionIsValidbaseType.ts, 0, 79)) | ||
|
||
SuperClass: K | ||
>SuperClass : Symbol(SuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 9, 73)) | ||
>K : Symbol(K, Decl(mixinIntersectionIsValidbaseType.ts, 9, 29)) | ||
|
||
) => { | ||
const LocalMixin = (InnerSuperClass: K) => { | ||
>LocalMixin : Symbol(LocalMixin, Decl(mixinIntersectionIsValidbaseType.ts, 12, 9)) | ||
>InnerSuperClass : Symbol(InnerSuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 12, 24)) | ||
>K : Symbol(K, Decl(mixinIntersectionIsValidbaseType.ts, 9, 29)) | ||
|
||
return class SerializableLocal extends InnerSuperClass { | ||
>SerializableLocal : Symbol(SerializableLocal, Decl(mixinIntersectionIsValidbaseType.ts, 13, 14)) | ||
>InnerSuperClass : Symbol(InnerSuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 12, 24)) | ||
} | ||
}; | ||
let ResultClass = LocalMixin(SuperClass); | ||
>ResultClass : Symbol(ResultClass, Decl(mixinIntersectionIsValidbaseType.ts, 16, 7)) | ||
>LocalMixin : Symbol(LocalMixin, Decl(mixinIntersectionIsValidbaseType.ts, 12, 9)) | ||
>SuperClass : Symbol(SuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 9, 73)) | ||
|
||
return ResultClass; | ||
>ResultClass : Symbol(ResultClass, Decl(mixinIntersectionIsValidbaseType.ts, 16, 7)) | ||
|
||
}; | ||
|
||
const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => { | ||
>AMixin : Symbol(AMixin, Decl(mixinIntersectionIsValidbaseType.ts, 20, 5)) | ||
>K : Symbol(K, Decl(mixinIntersectionIsValidbaseType.ts, 20, 16)) | ||
>Constructor : Symbol(Constructor, Decl(mixinIntersectionIsValidbaseType.ts, 0, 0)) | ||
>Initable : Symbol(Initable, Decl(mixinIntersectionIsValidbaseType.ts, 0, 79)) | ||
>Initable : Symbol(Initable, Decl(mixinIntersectionIsValidbaseType.ts, 0, 79)) | ||
>SuperClass : Symbol(SuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 20, 60)) | ||
>K : Symbol(K, Decl(mixinIntersectionIsValidbaseType.ts, 20, 16)) | ||
|
||
let SomeHowOkay = class A extends SuperClass { | ||
>SomeHowOkay : Symbol(SomeHowOkay, Decl(mixinIntersectionIsValidbaseType.ts, 21, 7)) | ||
>A : Symbol(A, Decl(mixinIntersectionIsValidbaseType.ts, 21, 21)) | ||
>SuperClass : Symbol(SuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 20, 60)) | ||
|
||
}; | ||
|
||
let SomeHowNotOkay = class A extends Serializable(SuperClass) { | ||
>SomeHowNotOkay : Symbol(SomeHowNotOkay, Decl(mixinIntersectionIsValidbaseType.ts, 24, 7)) | ||
>A : Symbol(A, Decl(mixinIntersectionIsValidbaseType.ts, 24, 24)) | ||
>Serializable : Symbol(Serializable, Decl(mixinIntersectionIsValidbaseType.ts, 9, 12)) | ||
>SuperClass : Symbol(SuperClass, Decl(mixinIntersectionIsValidbaseType.ts, 20, 60)) | ||
|
||
}; | ||
}; |
67 changes: 67 additions & 0 deletions
67
tests/baselines/reference/mixinIntersectionIsValidbaseType.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
=== tests/cases/compiler/mixinIntersectionIsValidbaseType.ts === | ||
export type Constructor<T extends object = object> = new (...args: any[]) => T; | ||
>Constructor : Constructor<T> | ||
>args : any[] | ||
|
||
export interface Initable { | ||
init(...args: any[]): void; | ||
>init : (...args: any[]) => void | ||
>args : any[] | ||
} | ||
|
||
/** | ||
* Plain mixin where the superclass must be Initable | ||
*/ | ||
export const Serializable = <K extends Constructor<Initable> & Initable>( | ||
>Serializable : <K extends Constructor<Initable> & Initable>(SuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
><K extends Constructor<Initable> & Initable>( SuperClass: K) => { const LocalMixin = (InnerSuperClass: K) => { return class SerializableLocal extends InnerSuperClass { } }; let ResultClass = LocalMixin(SuperClass); return ResultClass;} : <K extends Constructor<Initable> & Initable>(SuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
|
||
SuperClass: K | ||
>SuperClass : K | ||
|
||
) => { | ||
const LocalMixin = (InnerSuperClass: K) => { | ||
>LocalMixin : (InnerSuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>(InnerSuperClass: K) => { return class SerializableLocal extends InnerSuperClass { } } : (InnerSuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>InnerSuperClass : K | ||
|
||
return class SerializableLocal extends InnerSuperClass { | ||
>class SerializableLocal extends InnerSuperClass { } : { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>SerializableLocal : { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>InnerSuperClass : Initable | ||
} | ||
}; | ||
let ResultClass = LocalMixin(SuperClass); | ||
>ResultClass : { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>LocalMixin(SuperClass) : { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>LocalMixin : (InnerSuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>SuperClass : K | ||
|
||
return ResultClass; | ||
>ResultClass : { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
|
||
}; | ||
|
||
const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => { | ||
>AMixin : <K extends Constructor<Initable> & Initable>(SuperClass: K) => void | ||
><K extends Constructor<Initable> & Initable>(SuperClass: K) => { let SomeHowOkay = class A extends SuperClass { }; let SomeHowNotOkay = class A extends Serializable(SuperClass) { };} : <K extends Constructor<Initable> & Initable>(SuperClass: K) => void | ||
>SuperClass : K | ||
|
||
let SomeHowOkay = class A extends SuperClass { | ||
>SomeHowOkay : { new (...args: any[]): A; prototype: AMixin<any>.A; init(...args: any[]): void; } & K | ||
>class A extends SuperClass { } : { new (...args: any[]): A; prototype: AMixin<any>.A; init(...args: any[]): void; } & K | ||
>A : { new (...args: any[]): A; prototype: AMixin<any>.A; init(...args: any[]): void; } & K | ||
>SuperClass : Initable | ||
|
||
}; | ||
|
||
let SomeHowNotOkay = class A extends Serializable(SuperClass) { | ||
>SomeHowNotOkay : { new (...args: any[]): A; prototype: AMixin<any>.A; init: (...args: any[]) => void; } & K | ||
>class A extends Serializable(SuperClass) { } : { new (...args: any[]): A; prototype: AMixin<any>.A; init: (...args: any[]) => void; } & K | ||
>A : { new (...args: any[]): A; prototype: AMixin<any>.A; init: (...args: any[]) => void; } & K | ||
>Serializable(SuperClass) : Serializable<K>.SerializableLocal & Initable | ||
>Serializable : <K extends Constructor<Initable> & Initable>(SuperClass: K) => { new (...args: any[]): SerializableLocal; prototype: Serializable<any>.SerializableLocal; init(...args: any[]): void; } & K | ||
>SuperClass : K | ||
|
||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export type Constructor<T extends object = object> = new (...args: any[]) => T; | ||
|
||
export interface Initable { | ||
init(...args: any[]): void; | ||
} | ||
|
||
/** | ||
* Plain mixin where the superclass must be Initable | ||
*/ | ||
export const Serializable = <K extends Constructor<Initable> & Initable>( | ||
SuperClass: K | ||
) => { | ||
const LocalMixin = (InnerSuperClass: K) => { | ||
return class SerializableLocal extends InnerSuperClass { | ||
} | ||
}; | ||
let ResultClass = LocalMixin(SuperClass); | ||
return ResultClass; | ||
}; | ||
|
||
const AMixin = <K extends Constructor<Initable> & Initable>(SuperClass: K) => { | ||
let SomeHowOkay = class A extends SuperClass { | ||
}; | ||
|
||
let SomeHowNotOkay = class A extends Serializable(SuperClass) { | ||
}; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.