Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3458,11 +3458,7 @@ namespace ts {
return symbolToTypeNode(typeAlias, context, SymbolFlags.Type);
}
else {
context.approximateLength += 3;
if (!(context.flags & NodeBuilderFlags.NoTruncation)) {
return createTypeReferenceNode(createIdentifier("..."), /*typeArguments*/ undefined);
}
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
return createElidedInformationPlaceholder(context);
}
}
else {
Expand All @@ -3477,11 +3473,7 @@ namespace ts {

const depth = context.symbolDepth.get(id) || 0;
if (depth > 10) {
context.approximateLength += 3;
if (!(context.flags & NodeBuilderFlags.NoTruncation)) {
return createTypeReferenceNode(createIdentifier("..."), /*typeArguments*/ undefined);
}
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
return createElidedInformationPlaceholder(context);
}
context.symbolDepth.set(id, depth + 1);
context.visitedTypes.set(typeId, true);
Expand Down Expand Up @@ -3674,10 +3666,15 @@ namespace ts {
typeElements.push(<ConstructSignatureDeclaration>signatureToSignatureDeclarationHelper(signature, SyntaxKind.ConstructSignature, context));
}
if (resolvedType.stringIndexInfo) {
const indexInfo = resolvedType.objectFlags & ObjectFlags.ReverseMapped ?
createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration) :
resolvedType.stringIndexInfo;
typeElements.push(indexInfoToIndexSignatureDeclarationHelper(indexInfo, IndexKind.String, context));
let indexSignature: IndexSignatureDeclaration;
if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) {
indexSignature = indexInfoToIndexSignatureDeclarationHelper(createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration), IndexKind.String, context);
indexSignature.type = createElidedInformationPlaceholder(context);
}
else {
indexSignature = indexInfoToIndexSignatureDeclarationHelper(resolvedType.stringIndexInfo, IndexKind.String, context);
}
typeElements.push(indexSignature);
}
if (resolvedType.numberIndexInfo) {
typeElements.push(indexInfoToIndexSignatureDeclarationHelper(resolvedType.numberIndexInfo, IndexKind.Number, context));
Expand Down Expand Up @@ -3711,8 +3708,17 @@ namespace ts {
}
}

function createElidedInformationPlaceholder(context: NodeBuilderContext) {
context.approximateLength += 3;
if (!(context.flags & NodeBuilderFlags.NoTruncation)) {
return createTypeReferenceNode(createIdentifier("..."), /*typeArguments*/ undefined);
}
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
}

function addPropertyToElementList(propertySymbol: Symbol, context: NodeBuilderContext, typeElements: TypeElement[]) {
const propertyType = getCheckFlags(propertySymbol) & CheckFlags.ReverseMapped && context.flags & NodeBuilderFlags.InReverseMappedType ?
const propertyIsReverseMapped = !!(getCheckFlags(propertySymbol) & CheckFlags.ReverseMapped);
const propertyType = propertyIsReverseMapped && context.flags & NodeBuilderFlags.InReverseMappedType ?
anyType : getTypeOfSymbol(propertySymbol);
const saveEnclosingDeclaration = context.enclosingDeclaration;
context.enclosingDeclaration = undefined;
Expand Down Expand Up @@ -3741,8 +3747,14 @@ namespace ts {
}
else {
const savedFlags = context.flags;
context.flags |= !!(getCheckFlags(propertySymbol) & CheckFlags.ReverseMapped) ? NodeBuilderFlags.InReverseMappedType : 0;
const propertyTypeNode = propertyType ? typeToTypeNodeHelper(propertyType, context) : createKeywordTypeNode(SyntaxKind.AnyKeyword);
context.flags |= propertyIsReverseMapped ? NodeBuilderFlags.InReverseMappedType : 0;
let propertyTypeNode: TypeNode;
if (propertyIsReverseMapped && !!(savedFlags & NodeBuilderFlags.InReverseMappedType)) {
propertyTypeNode = createElidedInformationPlaceholder(context);
}
else {
propertyTypeNode = propertyType ? typeToTypeNodeHelper(propertyType, context) : createKeywordTypeNode(SyntaxKind.AnyKeyword);
}
context.flags = savedFlags;

const modifiers = isReadonlySymbol(propertySymbol) ? [createToken(SyntaxKind.ReadonlyKeyword)] : undefined;
Expand Down
28 changes: 14 additions & 14 deletions tests/cases/fourslash/quickInfoMappedTypeRecursiveInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,53 @@

verify.quickInfoAt('1', `const out: {
a: {
a: any;
a: ...;
};
}`);
verify.quickInfoAt('2', `function foo<{
a: {
a: any;
a: ...;
};
}>(deep: Deep<{
a: {
a: any;
a: ...;
};
}>): {
a: {
a: any;
a: ...;
};
}`);
verify.quickInfoAt('3', `(property) a: {
a: {
a: any;
a: ...;
};
}`);
verify.quickInfoAt('4', `(property) a: {
a: {
a: any;
a: ...;
};
}`);
verify.quickInfoAt('5', `(property) a: {
a: {
a: any;
a: ...;
};
}`);
verify.quickInfoAt('6', `const oub: {
[x: string]: any;
[x: string]: ...;
}`);
verify.quickInfoAt('7', `function foo<{
[x: string]: any;
[x: string]: ...;
}>(deep: Deep<{
[x: string]: any;
[x: string]: ...;
}>): {
[x: string]: any;
[x: string]: ...;
}`);
verify.quickInfoAt('8', `{
[x: string]: any;
[x: string]: ...;
}`);
verify.quickInfoAt('9', `{
[x: string]: any;
[x: string]: ...;
}`);
verify.quickInfoAt('10', `{
[x: string]: any;
[x: string]: ...;
}`);
36 changes: 36 additions & 0 deletions tests/cases/fourslash/reverseMappedTypeQuickInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference path="fourslash.ts" />

////interface IAction {
//// type: string;
////}
////
////type Reducer<S> = (state: S, action: IAction) => S
////
////function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
//// const dummy = {} as S;
//// return () => dummy;
////}
////
////const test_inner = (test: string, action: IAction) => {
//// return 'dummy';
////}
////const test = combineReducers({
//// test_inner
////});
////
////const test_outer = combineReducers({
//// test
////});
////
////// '{test: { test_inner: any } }'
////type FinalType/*1*/ = ReturnType<typeof test_outer>;
////
////var k: FinalType;
////k.test.test_inner/*2*/

verify.quickInfoAt("1", `type FinalType = {
test: {
test_inner: ...;
};
}`);
verify.quickInfoAt("2", `(property) test_inner: string`);