@@ -2295,12 +2295,12 @@ namespace ts {
2295
2295
? chainDiagnosticMessages(
2296
2296
/*details*/ undefined,
2297
2297
Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1,
2298
- packageId.name, getMangledNameForScopedPackage (packageId.name))
2298
+ packageId.name, mangleScopedPackageName (packageId.name))
2299
2299
: chainDiagnosticMessages(
2300
2300
/*details*/ undefined,
2301
2301
Diagnostics.Try_npm_install_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0,
2302
2302
moduleReference,
2303
- getMangledNameForScopedPackage (packageId.name))
2303
+ mangleScopedPackageName (packageId.name))
2304
2304
: undefined;
2305
2305
errorOrSuggestion(isError, errorNode, chainDiagnosticMessages(
2306
2306
errorInfo,
@@ -5910,9 +5910,9 @@ namespace ts {
5910
5910
for (const declaration of symbol.declarations) {
5911
5911
if (declaration.kind === SyntaxKind.EnumDeclaration) {
5912
5912
for (const member of (<EnumDeclaration>declaration).members) {
5913
- const memberType = getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member)); // TODO: GH#18217
5913
+ const memberType = getFreshTypeOfLiteralType( getLiteralType(getEnumMemberValue(member)!, enumCount, getSymbolOfNode(member) )); // TODO: GH#18217
5914
5914
getSymbolLinks(getSymbolOfNode(member)).declaredType = memberType;
5915
- memberTypeList.push(memberType);
5915
+ memberTypeList.push(getRegularTypeOfLiteralType( memberType) );
5916
5916
}
5917
5917
}
5918
5918
}
@@ -8249,7 +8249,7 @@ namespace ts {
8249
8249
const res = tryGetDeclaredTypeOfSymbol(symbol);
8250
8250
if (res) {
8251
8251
return checkNoTypeArguments(node, symbol) ?
8252
- res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : res :
8252
+ res.flags & TypeFlags.TypeParameter ? getConstrainedTypeVariable(<TypeParameter>res, node) : getRegularTypeOfLiteralType( res) :
8253
8253
errorType;
8254
8254
}
8255
8255
@@ -12743,7 +12743,7 @@ namespace ts {
12743
12743
}
12744
12744
12745
12745
function getWidenedLiteralType(type: Type): Type {
12746
- return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
12746
+ return type.flags & TypeFlags.EnumLiteral && type.flags & TypeFlags.FreshLiteral ? getBaseTypeOfEnumLiteralType(<LiteralType>type) :
12747
12747
type.flags & TypeFlags.StringLiteral && type.flags & TypeFlags.FreshLiteral ? stringType :
12748
12748
type.flags & TypeFlags.NumberLiteral && type.flags & TypeFlags.FreshLiteral ? numberType :
12749
12749
type.flags & TypeFlags.BooleanLiteral ? booleanType :
@@ -19217,12 +19217,16 @@ namespace ts {
19217
19217
let aboveArgCount = Number.POSITIVE_INFINITY;
19218
19218
19219
19219
let argCount = args.length;
19220
+ let closestSignature: Signature | undefined;
19220
19221
for (const sig of signatures) {
19221
19222
const minCount = getMinArgumentCount(sig);
19222
19223
const maxCount = getParameterCount(sig);
19223
19224
if (minCount < argCount && minCount > belowArgCount) belowArgCount = minCount;
19224
19225
if (argCount < maxCount && maxCount < aboveArgCount) aboveArgCount = maxCount;
19225
- min = Math.min(min, minCount);
19226
+ if (minCount < min) {
19227
+ min = minCount;
19228
+ closestSignature = sig;
19229
+ }
19226
19230
max = Math.max(max, maxCount);
19227
19231
}
19228
19232
@@ -19235,16 +19239,29 @@ namespace ts {
19235
19239
argCount--;
19236
19240
}
19237
19241
19242
+ let related: DiagnosticWithLocation | undefined;
19243
+ if (closestSignature && getMinArgumentCount(closestSignature) > argCount && closestSignature.declaration) {
19244
+ const paramDecl = closestSignature.declaration.parameters[closestSignature.thisParameter ? argCount + 1 : argCount];
19245
+ if (paramDecl) {
19246
+ related = createDiagnosticForNode(
19247
+ paramDecl,
19248
+ isBindingPattern(paramDecl.name) ? Diagnostics.An_argument_matching_this_binding_pattern_was_not_provided : Diagnostics.An_argument_for_0_was_not_provided,
19249
+ !paramDecl.name ? argCount : !isBindingPattern(paramDecl.name) ? idText(getFirstIdentifier(paramDecl.name)) : undefined
19250
+ );
19251
+ }
19252
+ }
19238
19253
if (hasRestParameter || hasSpreadArgument) {
19239
19254
const error = hasRestParameter && hasSpreadArgument ? Diagnostics.Expected_at_least_0_arguments_but_got_1_or_more :
19240
19255
hasRestParameter ? Diagnostics.Expected_at_least_0_arguments_but_got_1 :
19241
19256
Diagnostics.Expected_0_arguments_but_got_1_or_more;
19242
- return createDiagnosticForNode(node, error, paramRange, argCount);
19257
+ const diagnostic = createDiagnosticForNode(node, error, paramRange, argCount);
19258
+ return related ? addRelatedInfo(diagnostic, related) : diagnostic;
19243
19259
}
19244
19260
if (min < argCount && argCount < max) {
19245
19261
return createDiagnosticForNode(node, Diagnostics.No_overload_expects_0_arguments_but_overloads_do_exist_that_expect_either_1_or_2_arguments, argCount, belowArgCount, aboveArgCount);
19246
19262
}
19247
- return createDiagnosticForNode(node, Diagnostics.Expected_0_arguments_but_got_1, paramRange, argCount);
19263
+ const diagnostic = createDiagnosticForNode(node, Diagnostics.Expected_0_arguments_but_got_1, paramRange, argCount);
19264
+ return related ? addRelatedInfo(diagnostic, related) : diagnostic;
19248
19265
}
19249
19266
19250
19267
function getTypeArgumentArityError(node: Node, signatures: ReadonlyArray<Signature>, typeArguments: NodeArray<TypeNode>) {
@@ -28286,13 +28303,14 @@ namespace ts {
28286
28303
return false;
28287
28304
}
28288
28305
28289
- function literalTypeToNode(type: LiteralType): Expression {
28290
- return createLiteral(type.value);
28306
+ function literalTypeToNode(type: LiteralType, enclosing: Node): Expression {
28307
+ const enumResult = type.flags & TypeFlags.EnumLiteral && nodeBuilder.symbolToExpression(type.symbol, SymbolFlags.Value, enclosing);
28308
+ return enumResult || createLiteral(type.value);
28291
28309
}
28292
28310
28293
28311
function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
28294
28312
const type = getTypeOfSymbol(getSymbolOfNode(node));
28295
- return literalTypeToNode(<LiteralType>type);
28313
+ return literalTypeToNode(<LiteralType>type, node );
28296
28314
}
28297
28315
28298
28316
function createResolver(): EmitResolver {
@@ -29657,13 +29675,20 @@ namespace ts {
29657
29675
(<PrefixUnaryExpression>expr).operand.kind === SyntaxKind.NumericLiteral;
29658
29676
}
29659
29677
29678
+ function isSimpleLiteralEnumReference(expr: Expression) {
29679
+ if (
29680
+ (isPropertyAccessExpression(expr) || (isElementAccessExpression(expr) && isStringOrNumberLiteralExpression(expr.argumentExpression))) &&
29681
+ isEntityNameExpression(expr.expression)
29682
+ ) return !!(checkExpressionCached(expr).flags & TypeFlags.EnumLiteral);
29683
+ }
29684
+
29660
29685
function checkAmbientInitializer(node: VariableDeclaration | PropertyDeclaration | PropertySignature) {
29661
29686
if (node.initializer) {
29662
- const isInvalidInitializer = !isStringOrNumberLiteralExpression(node.initializer);
29687
+ const isInvalidInitializer = !( isStringOrNumberLiteralExpression(node.initializer) || isSimpleLiteralEnumReference(node.initializer) );
29663
29688
const isConstOrReadonly = isDeclarationReadonly(node) || isVariableDeclaration(node) && isVarConst(node);
29664
29689
if (isConstOrReadonly && !node.type) {
29665
29690
if (isInvalidInitializer) {
29666
- return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal );
29691
+ return grammarErrorOnNode(node.initializer!, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal_or_literal_enum_reference );
29667
29692
}
29668
29693
}
29669
29694
else {
0 commit comments