Skip to content

Commit 113338c

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map5
2 parents b98e82e + a36db0e commit 113338c

File tree

16 files changed

+193
-130
lines changed

16 files changed

+193
-130
lines changed

src/compiler/checker.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,15 +4762,15 @@ namespace ts {
47624762
getPropertiesOfObjectType(type);
47634763
}
47644764

4765-
function getConstraintOfTypeVariable(type: TypeVariable): Type {
4766-
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfTypeVariable(type);
4765+
function getConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
4766+
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) : getBaseConstraintOfType(type);
47674767
}
47684768

47694769
function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type {
47704770
return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined;
47714771
}
47724772

4773-
function getBaseConstraintOfTypeVariable(type: TypeVariable): Type {
4773+
function getBaseConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
47744774
const constraint = getResolvedBaseConstraint(type);
47754775
return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined;
47764776
}
@@ -4784,15 +4784,15 @@ namespace ts {
47844784
* type variable has no constraint, and the circularConstraintType singleton is returned if the constraint
47854785
* circularly references the type variable.
47864786
*/
4787-
function getResolvedBaseConstraint(type: TypeVariable): Type {
4787+
function getResolvedBaseConstraint(type: TypeVariable | UnionOrIntersectionType): Type {
47884788
let typeStack: Type[];
47894789
let circular: boolean;
4790-
if (!type.resolvedApparentType) {
4790+
if (!type.resolvedBaseConstraint) {
47914791
typeStack = [];
47924792
const constraint = getBaseConstraint(type);
4793-
type.resolvedApparentType = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
4793+
type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
47944794
}
4795-
return type.resolvedApparentType;
4795+
return type.resolvedBaseConstraint;
47964796

47974797
function getBaseConstraint(t: Type): Type {
47984798
if (contains(typeStack, t)) {
@@ -4843,7 +4843,7 @@ namespace ts {
48434843
* type itself. Note that the apparent type of a union type is the union type itself.
48444844
*/
48454845
function getApparentType(type: Type): Type {
4846-
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfTypeVariable(<TypeVariable>type) || emptyObjectType : type;
4846+
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType : type;
48474847
return t.flags & TypeFlags.StringLike ? globalStringType :
48484848
t.flags & TypeFlags.NumberLike ? globalNumberType :
48494849
t.flags & TypeFlags.BooleanLike ? globalBooleanType :
@@ -7441,16 +7441,6 @@ namespace ts {
74417441
}
74427442
}
74437443
}
7444-
else {
7445-
// Given a type parameter K with a constraint keyof T, a type S is
7446-
// assignable to K if S is assignable to keyof T.
7447-
const constraint = getConstraintOfTypeParameter(<TypeParameter>target);
7448-
if (constraint && constraint.flags & TypeFlags.Index) {
7449-
if (result = isRelatedTo(source, constraint, reportErrors)) {
7450-
return result;
7451-
}
7452-
}
7453-
}
74547444
}
74557445
else if (target.flags & TypeFlags.Index) {
74567446
// A keyof S is related to a keyof T if T is related to S.
@@ -7459,14 +7449,12 @@ namespace ts {
74597449
return result;
74607450
}
74617451
}
7462-
// Given a type variable T with a constraint C, a type S is assignable to
7463-
// keyof T if S is assignable to keyof C.
7464-
if ((<IndexType>target).type.flags & TypeFlags.TypeVariable) {
7465-
const constraint = getConstraintOfTypeVariable(<TypeVariable>(<IndexType>target).type);
7466-
if (constraint) {
7467-
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
7468-
return result;
7469-
}
7452+
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
7453+
// constraint of T.
7454+
const constraint = getConstraintOfType((<IndexType>target).type);
7455+
if (constraint) {
7456+
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
7457+
return result;
74707458
}
74717459
}
74727460
}
@@ -7480,7 +7468,7 @@ namespace ts {
74807468
}
74817469
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
74827470
// A is the apparent type of S.
7483-
const constraint = getBaseConstraintOfTypeVariable(<IndexedAccessType>target);
7471+
const constraint = getBaseConstraintOfType(<IndexedAccessType>target);
74847472
if (constraint) {
74857473
if (result = isRelatedTo(source, constraint, reportErrors)) {
74867474
errorInfo = saveErrorInfo;
@@ -7520,7 +7508,7 @@ namespace ts {
75207508
else if (source.flags & TypeFlags.IndexedAccess) {
75217509
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
75227510
// A is the apparent type of S.
7523-
const constraint = getBaseConstraintOfTypeVariable(<IndexedAccessType>source);
7511+
const constraint = getBaseConstraintOfType(<IndexedAccessType>source);
75247512
if (constraint) {
75257513
if (result = isRelatedTo(constraint, target, reportErrors)) {
75267514
errorInfo = saveErrorInfo;
@@ -15241,7 +15229,7 @@ namespace ts {
1524115229
function isLiteralContextualType(contextualType: Type) {
1524215230
if (contextualType) {
1524315231
if (contextualType.flags & TypeFlags.TypeVariable) {
15244-
const constraint = getBaseConstraintOfTypeVariable(<TypeVariable>contextualType) || emptyObjectType;
15232+
const constraint = getBaseConstraintOfType(<TypeVariable>contextualType) || emptyObjectType;
1524515233
// If the type parameter is constrained to the base primitive type we're checking for,
1524615234
// consider this a literal context. For example, given a type parameter 'T extends string',
1524715235
// this causes us to infer string literal types for T.

src/compiler/core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace ts {
4444
return new MapCtr<T>();
4545
}
4646

47-
//!!!
4847
export function createMapFromTemplate<T>(template?: MapLike<T>): Map<T> {
4948
const map: Map<T> = new MapCtr<T>();
5049

src/compiler/tsconfig.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
{
2+
"extends": "../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"noImplicitThis": true,
54
"removeComments": true,
6-
"preserveConstEnums": true,
7-
"pretty": true,
85
"outFile": "../../built/local/tsc.js",
9-
"sourceMap": true,
106
"declaration": true,
11-
"stripInternal": true,
12-
"target": "es5",
13-
"noUnusedLocals": true,
14-
"noUnusedParameters": true,
157
"types": [ ]
168
},
179
"files": [

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,8 @@
29422942
/* @internal */
29432943
resolvedIndexType: IndexType;
29442944
/* @internal */
2945+
resolvedBaseConstraint: Type;
2946+
/* @internal */
29452947
couldContainTypeVariables: boolean;
29462948
}
29472949

@@ -3001,7 +3003,7 @@
30013003

30023004
export interface TypeVariable extends Type {
30033005
/* @internal */
3004-
resolvedApparentType: Type;
3006+
resolvedBaseConstraint: Type;
30053007
/* @internal */
30063008
resolvedIndexType: IndexType;
30073009
}

src/harness/tsconfig.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
{
2+
"extends": "../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"pretty": true,
54
"removeComments": false,
6-
"preserveConstEnums": true,
75
"outFile": "../../built/local/run.js",
8-
"sourceMap": true,
96
"declaration": false,
10-
"stripInternal": true,
117
"types": [
128
"node", "mocha", "chai"
13-
],
14-
"target": "es5",
15-
"noUnusedLocals": true,
16-
"noUnusedParameters": true
9+
]
1710
},
1811
"files": [
1912
"../compiler/core.ts",
@@ -85,7 +78,7 @@
8578
"../services/codefixes/importFixes.ts",
8679
"../services/codefixes/unusedIdentifierFixes.ts",
8780
"../services/harness.ts",
88-
81+
8982
"sourceMapRecorder.ts",
9083
"harnessLanguageService.ts",
9184
"fourslash.ts",

src/server/cancellationToken/tsconfig.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
{
2+
"extends": "../../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"noImplicitThis": true,
54
"removeComments": true,
6-
"preserveConstEnums": true,
7-
"pretty": true,
85
"module": "commonjs",
9-
"sourceMap": true,
10-
"stripInternal": true,
116
"types": [
127
"node"
13-
],
14-
"target": "es5",
15-
"noUnusedLocals": true,
16-
"noUnusedParameters": true
8+
]
179
},
1810
"files": [
1911
"cancellationToken.ts"

src/server/tsconfig.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
{
2+
"extends": "../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"noImplicitThis": true,
54
"removeComments": true,
6-
"preserveConstEnums": true,
7-
"pretty": true,
85
"outFile": "../../built/local/tsserver.js",
9-
"sourceMap": true,
10-
"stripInternal": true,
116
"types": [
127
"node"
13-
],
14-
"target": "es5",
15-
"noUnusedLocals": true,
16-
"noUnusedParameters": true
8+
]
179
},
1810
"files": [
1911
"../services/shims.ts",

src/server/typingsInstaller/tsconfig.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
{
2+
"extends": "../../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"noImplicitThis": true,
54
"removeComments": true,
6-
"preserveConstEnums": true,
7-
"pretty": true,
85
"outFile": "../../../built/local/typingsInstaller.js",
9-
"sourceMap": true,
10-
"stripInternal": true,
116
"types": [
127
"node"
13-
],
14-
"target": "es5",
15-
"noUnusedLocals": true,
16-
"noUnusedParameters": true
8+
]
179
},
1810
"files": [
1911
"../types.ts",

src/services/codefixes/importFixes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ namespace ts.codefix {
422422
const options = context.program.getCompilerOptions();
423423

424424
return tryGetModuleNameFromAmbientModule() ||
425-
tryGetModuleNameFromBaseUrl() ||
426-
tryGetModuleNameFromRootDirs() ||
427425
tryGetModuleNameFromTypeRoots() ||
428426
tryGetModuleNameAsNodeModule() ||
427+
tryGetModuleNameFromBaseUrl() ||
428+
tryGetModuleNameFromRootDirs() ||
429429
removeFileExtension(getRelativePath(moduleFileName, sourceDirectory));
430430

431431
function tryGetModuleNameFromAmbientModule(): string {

src/services/tsconfig.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
{
2+
"extends": "../tsconfig-base",
23
"compilerOptions": {
3-
"noImplicitAny": true,
4-
"noImplicitThis": true,
54
"removeComments": false,
6-
"preserveConstEnums": true,
7-
"pretty": true,
85
"outFile": "../../built/local/typescriptServices.js",
9-
"sourceMap": true,
10-
"stripInternal": true,
11-
"noResolve": false,
126
"declaration": true,
13-
"target": "es5",
14-
"noUnusedLocals": true,
15-
"noUnusedParameters": true,
167
"types": []
178
},
189
"files": [

0 commit comments

Comments
 (0)