improvements based on comments
This commit is contained in:
Родитель
bc2b105037
Коммит
67573be641
|
@ -44,3 +44,4 @@ internal/
|
|||
.settings
|
||||
.vscode/*
|
||||
!.vscode/tasks.json
|
||||
.idea
|
|
@ -3854,6 +3854,11 @@ namespace ts {
|
|||
return false;
|
||||
}
|
||||
|
||||
function typeHasCallSignatures(type: Type): boolean {
|
||||
const callSignature = getSignaturesOfType(type, SignatureKind.Call);
|
||||
return !!callSignature.length;
|
||||
}
|
||||
|
||||
function typeHasCallOrConstructSignatures(type: Type): boolean {
|
||||
const apparentType = getApparentType(type);
|
||||
if (apparentType.flags & TypeFlags.StructuredType) {
|
||||
|
@ -9496,7 +9501,7 @@ namespace ts {
|
|||
error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType));
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
|
||||
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
|
||||
}
|
||||
return resolveErrorCall(node);
|
||||
}
|
||||
|
@ -9586,7 +9591,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
if (!callSignatures.length) {
|
||||
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
|
||||
error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
|
||||
return resolveErrorCall(node);
|
||||
}
|
||||
|
||||
|
@ -9633,7 +9638,7 @@ namespace ts {
|
|||
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
||||
if (!callSignatures.length) {
|
||||
let errorInfo: DiagnosticMessageChain;
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType));
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, headMessage);
|
||||
diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo));
|
||||
return resolveErrorCall(node);
|
||||
|
|
|
@ -16,9 +16,9 @@ unionOfDifferentReturnType1(true); // error in type of parameter
|
|||
unionOfDifferentReturnType1(); // error missing parameter
|
||||
|
||||
var unionOfDifferentParameterTypes: { (a: number): number; } | { (a: string): Date; };
|
||||
unionOfDifferentParameterTypes(10); //no error
|
||||
unionOfDifferentParameterTypes("hello"); //no error
|
||||
unionOfDifferentParameterTypes(); //error TS2346
|
||||
unionOfDifferentParameterTypes(10);// error - no call signatures
|
||||
unionOfDifferentParameterTypes("hello");// error - no call signatures
|
||||
unionOfDifferentParameterTypes();// error - no call signatures
|
||||
|
||||
var unionOfDifferentNumberOfSignatures: { (a: number): number; } | { (a: number): Date; (a: string): boolean; };
|
||||
unionOfDifferentNumberOfSignatures(); // error - no call signatures
|
||||
|
@ -26,9 +26,9 @@ unionOfDifferentNumberOfSignatures(10); // error - no call signatures
|
|||
unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures
|
||||
|
||||
var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ;
|
||||
unionWithDifferentParameterCount(); //error TS2346
|
||||
unionWithDifferentParameterCount("hello"); //no error
|
||||
unionWithDifferentParameterCount("hello", 10); //no error
|
||||
unionWithDifferentParameterCount();// no call signature
|
||||
unionWithDifferentParameterCount("hello");// no call signature
|
||||
unionWithDifferentParameterCount("hello", 10);// no call signature
|
||||
|
||||
var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; };
|
||||
strOrNum = unionWithOptionalParameter1('hello');
|
||||
|
@ -71,4 +71,4 @@ strOrNum = unionWithRestParameter3(); // error no call signature
|
|||
|
||||
var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; };
|
||||
strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature
|
||||
strOrNum = unionWithRestParameter4("hello", "world");
|
||||
strOrNum = unionWithRestParameter4("hello", "world");
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
interface A {
|
||||
(number) : number;
|
||||
}
|
||||
|
||||
var f1: string | number;
|
||||
f1(); //error TS2658
|
||||
|
||||
var f2: string | A;
|
||||
f2(); //error TS2658
|
||||
|
||||
var f3: string[] | number[];
|
||||
f3.map(value=>value); //should not throw TS2349
|
|
@ -41,7 +41,8 @@ str = x.commonMethodType(str); // (a: string) => string so result should be stri
|
|||
strOrNum = x.commonPropertyDifferenType;
|
||||
strOrNum = x.commonMethodDifferentReturnType(str); // string | union
|
||||
x.commonMethodDifferentParameterType; // No error - property exists
|
||||
x.commonMethodDifferentParameterType(strOrNum); //error - TS2345
|
||||
x.commonMethodDifferentParameterType(strOrNum); // error - no call signatures because the type of this property is ((a: string) => string) | (a: number) => number
|
||||
// and the call signatures arent identical
|
||||
num = x.commonMethodWithTypeParameter(num);
|
||||
num = x.commonMethodWithOwnTypeParameter(num);
|
||||
str = x.commonMethodWithOwnTypeParameter(str);
|
||||
|
|
Загрузка…
Ссылка в новой задаче