@@ -3504,15 +3504,19 @@ namespace ts {
3504
3504
return isPrivateWithinAmbient(memberDeclaration);
3505
3505
}
3506
3506
3507
- function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
3507
+ function getTypeOfVariableOrParameterOrProperty(symbol: Symbol, crazy?: boolean): Type {
3508
+ const declaration = symbol.valueDeclaration;
3509
+ if (crazy && declaration.kind === SyntaxKind.Parameter && (declaration as ParameterDeclaration).contextualType) {
3510
+ // TODO: Doesn't widen of course
3511
+ return getTypeFromTypeNode((declaration as ParameterDeclaration).contextualType);
3512
+ }
3508
3513
const links = getSymbolLinks(symbol);
3509
3514
if (!links.type) {
3510
3515
// Handle prototype property
3511
3516
if (symbol.flags & SymbolFlags.Prototype) {
3512
3517
return links.type = getTypeOfPrototypeProperty(symbol);
3513
3518
}
3514
3519
// Handle catch clause variables
3515
- const declaration = symbol.valueDeclaration;
3516
3520
if (isCatchClauseVariableDeclarationOrBindingElement(declaration)) {
3517
3521
return links.type = anyType;
3518
3522
}
@@ -3695,13 +3699,16 @@ namespace ts {
3695
3699
return links.type;
3696
3700
}
3697
3701
3698
- function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
3702
+ function getTypeOfInstantiatedSymbol(symbol: Symbol, crazy?: boolean ): Type {
3699
3703
const links = getSymbolLinks(symbol);
3704
+ if (crazy) {
3705
+ return instantiateType(getTypeOfSymbol(links.target, crazy), links.mapper);
3706
+ }
3700
3707
if (!links.type) {
3701
3708
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
3702
3709
return unknownType;
3703
3710
}
3704
- let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
3711
+ let type = instantiateType(getTypeOfSymbol(links.target, crazy ), links.mapper);
3705
3712
if (!popTypeResolution()) {
3706
3713
type = reportCircularityError(symbol);
3707
3714
}
@@ -3725,12 +3732,12 @@ namespace ts {
3725
3732
return anyType;
3726
3733
}
3727
3734
3728
- function getTypeOfSymbol(symbol: Symbol): Type {
3735
+ function getTypeOfSymbol(symbol: Symbol, crazy?: boolean ): Type {
3729
3736
if (symbol.flags & SymbolFlags.Instantiated) {
3730
- return getTypeOfInstantiatedSymbol(symbol);
3737
+ return getTypeOfInstantiatedSymbol(symbol, crazy );
3731
3738
}
3732
3739
if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) {
3733
- return getTypeOfVariableOrParameterOrProperty(symbol);
3740
+ return getTypeOfVariableOrParameterOrProperty(symbol, crazy );
3734
3741
}
3735
3742
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
3736
3743
return getTypeOfFuncClassEnumModule(symbol);
@@ -9073,7 +9080,7 @@ namespace ts {
9073
9080
// We're inferring from some source type S to a mapped type { [P in T]: X }, where T is a type
9074
9081
// parameter. Infer from 'keyof S' to T and infer from a union of each property type in S to X.
9075
9082
inferFromTypes(getIndexType(source), constraintType);
9076
- inferFromTypes(getUnionType(map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(<MappedType>target));
9083
+ inferFromTypes(getUnionType(map(getPropertiesOfType(source), p => getTypeOfSymbol(p) )), getTemplateTypeFromMappedType(<MappedType>target));
9077
9084
return;
9078
9085
}
9079
9086
}
@@ -11262,7 +11269,7 @@ namespace ts {
11262
11269
const argIndex = indexOf(args, arg);
11263
11270
if (argIndex >= 0) {
11264
11271
const signature = getResolvedOrAnySignature(callTarget);
11265
- return getTypeAtPosition (signature, argIndex);
11272
+ return getSpecialContextualTypeAtPosition (signature, argIndex);
11266
11273
}
11267
11274
return undefined;
11268
11275
}
@@ -13097,7 +13104,7 @@ namespace ts {
13097
13104
// If the effective argument is 'undefined', then it is an argument that is present but is synthetic.
13098
13105
if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) {
13099
13106
// Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter)
13100
- const paramType = getTypeAtPosition (signature, i);
13107
+ const paramType = getSpecialContextualTypeAtPosition (signature, i);
13101
13108
let argType = getEffectiveArgumentType(node, i);
13102
13109
13103
13110
// If the effective argument type is 'undefined', there is no synthetic type
@@ -14121,8 +14128,8 @@ namespace ts {
14121
14128
}
14122
14129
}
14123
14130
14124
- function getTypeOfParameter(symbol: Symbol) {
14125
- const type = getTypeOfSymbol(symbol);
14131
+ function getTypeOfParameter(symbol: Symbol, crazy?: boolean ) {
14132
+ const type = getTypeOfSymbol(symbol, crazy );
14126
14133
if (strictNullChecks) {
14127
14134
const declaration = symbol.valueDeclaration;
14128
14135
if (declaration && (<VariableLikeDeclaration>declaration).initializer) {
@@ -14132,6 +14139,12 @@ namespace ts {
14132
14139
return type;
14133
14140
}
14134
14141
14142
+ function getSpecialContextualTypeAtPosition(signature: Signature, pos: number): Type {
14143
+ return signature.hasRestParameter ?
14144
+ pos < signature.parameters.length - 1 ? getTypeOfParameter(signature.parameters[pos], /*crazy*/ true) : getRestTypeOfSignature(signature) :
14145
+ pos < signature.parameters.length ? getTypeOfParameter(signature.parameters[pos], /*crazy*/ true) : anyType;
14146
+ }
14147
+
14135
14148
function getTypeAtPosition(signature: Signature, pos: number): Type {
14136
14149
return signature.hasRestParameter ?
14137
14150
pos < signature.parameters.length - 1 ? getTypeOfParameter(signature.parameters[pos]) : getRestTypeOfSignature(signature) :
0 commit comments