-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow extending from any #14935
Merged
Merged
Allow extending from any #14935
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f1c1969
Allow extending from any
sandersn 765ac7c
Improve handling of any as a base type
sandersn 650cc29
Test: extending from any
sandersn 3624417
Update baselines
sandersn 41eabbc
Re-swap mistakenly swapped lines of code
sandersn e09533d
Update test comments to match property names
sandersn 7f6c49e
Check TypeFlags.Any instead of anyType&unknownType
sandersn 75f1774
A few changes requested by review comments
sandersn 7e3c033
Unknown bases return baseConstructorType, not anyType
sandersn 441e54c
Update comment
sandersn 90d5c29
Remove special symbol for untyped modules
sandersn f635042
Improve test and comments
sandersn 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 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 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 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 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,21 @@ | ||
tests/cases/compiler/extendFromAny.ts(8,9): error TS2339: Property 'length' does not exist on type 'number'. | ||
tests/cases/compiler/extendFromAny.ts(9,10): error TS2339: Property 'length' does not exist on type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/extendFromAny.ts (2 errors) ==== | ||
declare var Base: any; | ||
class C extends Base { | ||
known = 1; | ||
static sknown = 2; | ||
} | ||
|
||
let c = new C(); | ||
c.known.length; // error, 'known' has no 'length' property | ||
~~~~~~ | ||
!!! error TS2339: Property 'length' does not exist on type 'number'. | ||
C.sknown.length; // error, 'sknown' has no 'length' property | ||
~~~~~~ | ||
!!! error TS2339: Property 'length' does not exist on type 'number'. | ||
c.unknown.length; // ok, unknown: any | ||
C.sunknown.length; // ok: sunknown: any | ||
|
This file contains 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,40 @@ | ||
//// [extendFromAny.ts] | ||
declare var Base: any; | ||
class C extends Base { | ||
known = 1; | ||
static sknown = 2; | ||
} | ||
|
||
let c = new C(); | ||
c.known.length; // error, 'known' has no 'length' property | ||
C.sknown.length; // error, 'sknown' has no 'length' property | ||
c.unknown.length; // ok, unknown: any | ||
C.sunknown.length; // ok: sunknown: any | ||
|
||
|
||
//// [extendFromAny.js] | ||
var __extends = (this && this.__extends) || (function () { | ||
var 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 function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var C = (function (_super) { | ||
__extends(C, _super); | ||
function C() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.known = 1; | ||
return _this; | ||
} | ||
return C; | ||
}(Base)); | ||
C.sknown = 2; | ||
var c = new C(); | ||
c.known.length; // error, 'known' has no 'length' property | ||
C.sknown.length; // error, 'sknown' has no 'length' property | ||
c.unknown.length; // ok, unknown: any | ||
C.sunknown.length; // ok: sunknown: any |
This file contains 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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
/a.ts(2,17): error TS2507: Type 'any' is not a constructor function type. | ||
/a.ts(2,8): error TS6133: 'Bar' is declared but never used. | ||
|
||
|
||
==== /a.ts (1 errors) ==== | ||
import Foo from "foo"; | ||
class A extends Foo { } | ||
~~~ | ||
!!! error TS2507: Type 'any' is not a constructor function type. | ||
import Bar from "bar"; // error: unused | ||
~~~ | ||
!!! error TS6133: 'Bar' is declared but never used. | ||
export class A extends Foo { } | ||
|
||
==== /node_modules/foo/index.js (0 errors) ==== | ||
// Test that extending an untyped module is an error, unlike extending unknownSymbol. | ||
|
||
This file is not read. | ||
|
||
==== /node_modules/bar/index.js (0 errors) ==== | ||
Nor is this one. | ||
|
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts(2,21): error TS2507: Type 'any' is not a constructor function type. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts(2,22): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts (2 errors) ==== | ||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts (1 errors) ==== | ||
function* g() { | ||
class C extends (yield 0) { } | ||
~~~~~~~~~ | ||
!!! error TS2507: Type 'any' is not a constructor function type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} |
This file contains 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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,29): error TS2507: Type 'any' is not a constructor function type. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,30): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts (2 errors) ==== | ||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts (1 errors) ==== | ||
function* g() { | ||
var x = class C extends (yield) {}; | ||
~~~~~~~ | ||
!!! error TS2507: Type 'any' is not a constructor function type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} |
This file contains 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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts(2,21): error TS2507: Type 'any' is not a constructor function type. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts(2,22): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts (2 errors) ==== | ||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts (1 errors) ==== | ||
function* g() { | ||
class C extends (yield) {}; | ||
~~~~~~~ | ||
!!! error TS2507: Type 'any' is not a constructor function type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the old name better, even if it's a bit long.