Skip to content

Commit 96e90dd

Browse files
author
Andy Hanson
committed
Merge branch 'master' into verifyCompletions
2 parents feb1c62 + 222f35d commit 96e90dd

File tree

156 files changed

+1756
-1081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1756
-1081
lines changed

src/compiler/checker.ts

Lines changed: 245 additions & 198 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,12 @@ namespace ts {
672672
category: Diagnostics.Advanced_Options,
673673
description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types,
674674
},
675+
{
676+
name: "keyofStringsOnly",
677+
type: "boolean",
678+
category: Diagnostics.Advanced_Options,
679+
description: Diagnostics.Resolve_keyof_to_string_valued_property_names_only_no_numbers_or_symbols,
680+
},
675681
{
676682
// A list of plugins to load in the language service
677683
name: "plugins",

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,10 @@
35263526
"category": "Message",
35273527
"code": 6194
35283528
},
3529+
"Resolve 'keyof' to string valued property names only (no numbers or symbols).": {
3530+
"category": "Message",
3531+
"code": 6195
3532+
},
35293533
"Variable '{0}' implicitly has an '{1}' type.": {
35303534
"category": "Error",
35313535
"code": 7005

src/compiler/types.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,7 @@ namespace ts {
33773377
/* @internal */ mergeId?: number; // Merge id (used to look up merged symbol)
33783378
/* @internal */ parent?: Symbol; // Parent symbol
33793379
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
3380+
/* @internal */ nameType?: Type; // Type associated with a late-bound symbol
33803381
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums
33813382
/* @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter.
33823383
/* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol?
@@ -3411,7 +3412,6 @@ namespace ts {
34113412
enumKind?: EnumKind; // Enum declaration classification
34123413
originatingImport?: ImportDeclaration | ImportCall; // Import declaration which produced the symbol, present if the symbol is marked as uncallable but had call signatures in `resolveESModuleSymbol`
34133414
lateSymbol?: Symbol; // Late-bound symbol for a computed property
3414-
nameType?: Type; // Type associate with a late-bound or mapped type property symbol's name
34153415
}
34163416

34173417
/* @internal */
@@ -3608,7 +3608,7 @@ namespace ts {
36083608
Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,
36093609
/* @internal */
36103610
Primitive = String | Number | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol,
3611-
StringLike = String | StringLiteral | Index,
3611+
StringLike = String | StringLiteral,
36123612
NumberLike = Number | NumberLiteral | Enum,
36133613
BooleanLike = Boolean | BooleanLiteral,
36143614
EnumLike = Enum | EnumLiteral,
@@ -3765,7 +3765,7 @@ namespace ts {
37653765
/* @internal */
37663766
resolvedIndexType: IndexType;
37673767
/* @internal */
3768-
resolvedDeclaredIndexType: IndexType;
3768+
resolvedStringIndexType: IndexType;
37693769
/* @internal */
37703770
resolvedBaseConstraint: Type;
37713771
/* @internal */
@@ -3854,7 +3854,7 @@ namespace ts {
38543854
/* @internal */
38553855
resolvedIndexType?: IndexType;
38563856
/* @internal */
3857-
resolvedDeclaredIndexType?: IndexType;
3857+
resolvedStringIndexType?: IndexType;
38583858
}
38593859

38603860
// Type parameters (TypeFlags.TypeParameter)
@@ -3886,9 +3886,9 @@ namespace ts {
38863886

38873887
// keyof T types (TypeFlags.Index)
38883888
export interface IndexType extends InstantiableType {
3889-
/* @internal */
3890-
isDeclaredType?: boolean;
38913889
type: InstantiableType | UnionOrIntersectionType;
3890+
/* @internal */
3891+
stringsOnly: boolean;
38923892
}
38933893

38943894
export interface ConditionalRoot {
@@ -4047,10 +4047,10 @@ namespace ts {
40474047

40484048
/* @internal */
40494049
export interface WideningContext {
4050-
parent?: WideningContext; // Parent context
4051-
propertyName?: __String; // Name of property in parent
4052-
siblings?: Type[]; // Types of siblings
4053-
resolvedPropertyNames?: __String[]; // Property names occurring in sibling object literals
4050+
parent?: WideningContext; // Parent context
4051+
propertyName?: __String; // Name of property in parent
4052+
siblings?: Type[]; // Types of siblings
4053+
resolvedProperties?: Symbol[]; // Properties occurring in sibling object literals
40544054
}
40554055

40564056
/* @internal */
@@ -4165,6 +4165,7 @@ namespace ts {
41654165
inlineSources?: boolean;
41664166
isolatedModules?: boolean;
41674167
jsx?: JsxEmit;
4168+
keyofStringsOnly?: boolean;
41684169
lib?: string[];
41694170
/*@internal*/listEmittedFiles?: boolean;
41704171
/*@internal*/listFiles?: boolean;

src/harness/fourslash.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,10 @@ namespace FourSlash {
278278
if (configFileName) {
279279
const baseDir = ts.normalizePath(ts.getDirectoryPath(configFileName));
280280
const host = new Utils.MockParseConfigHost(baseDir, /*ignoreCase*/ false, this.inputFiles);
281-
282-
const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles.get(configFileName));
283-
assert.isTrue(configJsonObj.config !== undefined);
284-
285-
compilationOptions = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir, compilationOptions, configFileName).options;
281+
const jsonSourceFile = ts.parseJsonText(configFileName, this.inputFiles.get(configFileName));
282+
compilationOptions = ts.parseJsonSourceFileConfigFileContent(jsonSourceFile, host, baseDir, compilationOptions, configFileName).options;
286283
}
287284

288-
289285
if (compilationOptions.typeRoots) {
290286
compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath));
291287
}
@@ -2498,14 +2494,7 @@ Actual: ${stringify(fullActual)}`);
24982494
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
24992495
this.goToMarker(markerName);
25002496

2501-
const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultPreferences, includeCompletionsForModuleExports: true }).entries.find(e =>
2502-
e.name === options.name && e.source === options.source);
2503-
2504-
if (!actualCompletion.hasAction) {
2505-
this.raiseError(`Completion for ${options.name} does not have an associated action.`);
2506-
}
2507-
2508-
const details = this.getCompletionEntryDetails(options.name, actualCompletion.source, options.preferences);
2497+
const details = this.getCompletionEntryDetails(options.name, options.source, options.preferences);
25092498
if (details.codeActions.length !== 1) {
25102499
this.raiseError(`Expected one code action, got ${details.codeActions.length}`);
25112500
}

src/lib/es2015.core.d.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
declare type PropertyKey = string | number | symbol;
2-
31
interface Array<T> {
42
/**
53
* Returns the value of the first element in the array where predicate is true, and undefined
@@ -258,20 +256,6 @@ interface NumberConstructor {
258256
parseInt(string: string, radix?: number): number;
259257
}
260258

261-
interface Object {
262-
/**
263-
* Determines whether an object has a property with the specified name.
264-
* @param v A property name.
265-
*/
266-
hasOwnProperty(v: PropertyKey): boolean;
267-
268-
/**
269-
* Determines whether a specified property is enumerable.
270-
* @param v A property name.
271-
*/
272-
propertyIsEnumerable(v: PropertyKey): boolean;
273-
}
274-
275259
interface ObjectConstructor {
276260
/**
277261
* Copy the values of all of the enumerable own properties from one or more source objects to a
@@ -327,25 +311,6 @@ interface ObjectConstructor {
327311
* @param proto The value of the new prototype or null.
328312
*/
329313
setPrototypeOf(o: any, proto: object | null): any;
330-
331-
/**
332-
* Gets the own property descriptor of the specified object.
333-
* An own property descriptor is one that is defined directly on the object and is not
334-
* inherited from the object's prototype.
335-
* @param o Object that contains the property.
336-
* @param p Name of the property.
337-
*/
338-
getOwnPropertyDescriptor(o: any, propertyKey: PropertyKey): PropertyDescriptor | undefined;
339-
340-
/**
341-
* Adds a property to an object, or modifies attributes of an existing property.
342-
* @param o Object on which to add or modify the property. This can be a native JavaScript
343-
* object (that is, a user-defined object or a built in object) or a DOM object.
344-
* @param p The property name.
345-
* @param attributes Descriptor for the property. It can be for a data property or an accessor
346-
* property.
347-
*/
348-
defineProperty(o: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): any;
349314
}
350315

351316
interface ReadonlyArray<T> {

src/lib/es5.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ declare function escape(string: string): string;
7474
*/
7575
declare function unescape(string: string): string;
7676

77+
declare type PropertyKey = string | number | symbol;
78+
7779
interface PropertyDescriptor {
7880
configurable?: boolean;
7981
enumerable?: boolean;
@@ -104,7 +106,7 @@ interface Object {
104106
* Determines whether an object has a property with the specified name.
105107
* @param v A property name.
106108
*/
107-
hasOwnProperty(v: string): boolean;
109+
hasOwnProperty(v: PropertyKey): boolean;
108110

109111
/**
110112
* Determines whether an object exists in another object's prototype chain.
@@ -116,7 +118,7 @@ interface Object {
116118
* Determines whether a specified property is enumerable.
117119
* @param v A property name.
118120
*/
119-
propertyIsEnumerable(v: string): boolean;
121+
propertyIsEnumerable(v: PropertyKey): boolean;
120122
}
121123

122124
interface ObjectConstructor {
@@ -139,7 +141,7 @@ interface ObjectConstructor {
139141
* @param o Object that contains the property.
140142
* @param p Name of the property.
141143
*/
142-
getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor | undefined;
144+
getOwnPropertyDescriptor(o: any, p: PropertyKey): PropertyDescriptor | undefined;
143145

144146
/**
145147
* Returns the names of the own properties of an object. The own properties of an object are those that are defined directly
@@ -167,7 +169,7 @@ interface ObjectConstructor {
167169
* @param p The property name.
168170
* @param attributes Descriptor for the property. It can be for a data property or an accessor property.
169171
*/
170-
defineProperty(o: any, p: string, attributes: PropertyDescriptor & ThisType<any>): any;
172+
defineProperty(o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): any;
171173

172174
/**
173175
* Adds one or more properties to an object, and/or modifies attributes of existing properties.
@@ -1340,7 +1342,7 @@ type Pick<T, K extends keyof T> = {
13401342
/**
13411343
* Construct a type with a set of properties K of type T
13421344
*/
1343-
type Record<K extends string, T> = {
1345+
type Record<K extends keyof any, T> = {
13441346
[P in K]: T;
13451347
};
13461348

src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,12 @@
903903
</Str>
904904
<Disp Icon="Str" />
905905
</Item>
906+
<Item ItemId=";Add_0_to_unresolved_variable_90008" ItemType="0" PsrId="306" Leaf="true">
907+
<Str Cat="Text">
908+
<Val><![CDATA[Add '{0}.' to unresolved variable]]></Val>
909+
</Str>
910+
<Disp Icon="Str" />
911+
</Item>
906912
<Item ItemId=";Add_all_missing_async_modifiers_95041" ItemType="0" PsrId="306" Leaf="true">
907913
<Str Cat="Text">
908914
<Val><![CDATA[Add all missing 'async' modifiers]]></Val>
@@ -999,24 +1005,9 @@
9991005
</Str>
10001006
<Disp Icon="Str" />
10011007
</Item>
1002-
<Item ItemId=";Add_this_to_all_unresolved_variables_matching_a_member_name_95037" ItemType="0" PsrId="306" Leaf="true">
1003-
<Str Cat="Text">
1004-
<Val><![CDATA[Add 'this.' to all unresolved variables matching a member name]]></Val>
1005-
<Tgt Cat="Text" Stat="Loc" Orig="New">
1006-
<Val><![CDATA[為所有用以比對成員名稱未解析的變數新增 'this.']]></Val>
1007-
</Tgt>
1008-
</Str>
1009-
<Disp Icon="Str" />
1010-
</Item>
1011-
<Item ItemId=";Add_this_to_unresolved_variable_90008" ItemType="0" PsrId="306" Leaf="true">
1008+
<Item ItemId=";Add_qualifier_to_all_unresolved_variables_matching_a_member_name_95037" ItemType="0" PsrId="306" Leaf="true">
10121009
<Str Cat="Text">
1013-
<Val><![CDATA[Add 'this.' to unresolved variable]]></Val>
1014-
<Tgt Cat="Text" Stat="Loc" Orig="New">
1015-
<Val><![CDATA[將 'this' 新增至未解析的變數]]></Val>
1016-
</Tgt>
1017-
<Prev Cat="Text">
1018-
<Val><![CDATA[Add 'this.' to unresolved variable.]]></Val>
1019-
</Prev>
1010+
<Val><![CDATA[Add qualifier to all unresolved variables matching a member name]]></Val>
10201011
</Str>
10211012
<Disp Icon="Str" />
10221013
</Item>
@@ -2388,15 +2379,6 @@
23882379
</Str>
23892380
<Disp Icon="Str" />
23902381
</Item>
2391-
<Item ItemId=";Compilation_complete_Watching_for_file_changes_6042" ItemType="0" PsrId="306" Leaf="true">
2392-
<Str Cat="Text">
2393-
<Val><![CDATA[Compilation complete. Watching for file changes.]]></Val>
2394-
<Tgt Cat="Text" Stat="Loc" Orig="New">
2395-
<Val><![CDATA[編譯完成。正在等候檔案變更。]]></Val>
2396-
</Tgt>
2397-
</Str>
2398-
<Disp Icon="Str" />
2399-
</Item>
24002382
<Item ItemId=";Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json_6020" ItemType="0" PsrId="306" Leaf="true">
24012383
<Str Cat="Text">
24022384
<Val><![CDATA[Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.]]></Val>
@@ -3771,20 +3753,20 @@
37713753
</Str>
37723754
<Disp Icon="Str" />
37733755
</Item>
3774-
<Item ItemId=";Found_0_errors_6194" ItemType="0" PsrId="306" Leaf="true">
3756+
<Item ItemId=";Found_0_errors_Watching_for_file_changes_6194" ItemType="0" PsrId="306" Leaf="true">
37753757
<Str Cat="Text">
3776-
<Val><![CDATA[Found {0} errors.]]></Val>
3758+
<Val><![CDATA[Found {0} errors. Watching for file changes.]]></Val>
37773759
<Tgt Cat="Text" Stat="Loc" Orig="New">
3778-
<Val><![CDATA[找到 {0} 個錯誤。]]></Val>
3760+
<Val><![CDATA[找到 {0} 個錯誤。正在監看檔案變更。]]></Val>
37793761
</Tgt>
37803762
</Str>
37813763
<Disp Icon="Str" />
37823764
</Item>
3783-
<Item ItemId=";Found_1_error_6193" ItemType="0" PsrId="306" Leaf="true">
3765+
<Item ItemId=";Found_1_error_Watching_for_file_changes_6193" ItemType="0" PsrId="306" Leaf="true">
37843766
<Str Cat="Text">
3785-
<Val><![CDATA[Found 1 error.]]></Val>
3767+
<Val><![CDATA[Found 1 error. Watching for file changes.]]></Val>
37863768
<Tgt Cat="Text" Stat="Loc" Orig="New">
3787-
<Val><![CDATA[找到 1 個錯誤。]]></Val>
3769+
<Val><![CDATA[找到 1 個錯誤。正在監看檔案變更。]]></Val>
37883770
</Tgt>
37893771
</Str>
37903772
<Disp Icon="Str" />

0 commit comments

Comments
 (0)