diff --git a/src/transformer/descriptor/descriptor.ts b/src/transformer/descriptor/descriptor.ts index 0986c3427..1d1fe769e 100644 --- a/src/transformer/descriptor/descriptor.ts +++ b/src/transformer/descriptor/descriptor.ts @@ -25,6 +25,7 @@ import { GetObjectLiteralDescriptor } from './objectLiteral/objectLiteral'; import { GetPropertyDescriptor } from './property/propertySignature'; import { GetStringDescriptor } from './string/string'; import { GetTypeAliasDescriptor } from './typeAlias/typeAlias'; +import { GetTypeLiteralDeclarationDescriptor } from './typeLiteral/typeLiteralDeclaration'; import { GetTypeParameterDescriptor } from './typeParameter/typeParameter'; import { GetTypeReferenceDescriptorReusable } from './typeReference/typeReferenceReusable'; import { GetUndefinedDescriptor } from './undefined/undefined'; @@ -37,6 +38,7 @@ export function GetDescriptor(node: ts.Node, scope: Scope): ts.Expression { case ts.SyntaxKind.TypeReference: return GetTypeReferenceDescriptorReusable(node as ts.TypeReferenceNode, scope); case ts.SyntaxKind.TypeLiteral: + return GetTypeLiteralDeclarationDescriptor(node as ts.InterfaceDeclaration, scope); case ts.SyntaxKind.InterfaceDeclaration: return GetInterfaceDeclarationDescriptor(node as ts.InterfaceDeclaration, scope); case ts.SyntaxKind.ClassDeclaration: diff --git a/src/transformer/descriptor/typeLiteral/typeLiteralDeclaration.ts b/src/transformer/descriptor/typeLiteral/typeLiteralDeclaration.ts new file mode 100644 index 000000000..4dcca57d9 --- /dev/null +++ b/src/transformer/descriptor/typeLiteral/typeLiteralDeclaration.ts @@ -0,0 +1,14 @@ +import * as ts from 'typescript'; +import { Scope } from '../../scope/scope'; +import { TypeChecker } from '../../typeChecker/typeChecker'; +import { GetMockPropertiesFromSymbol } from '../mock/mockProperties'; + +export function GetTypeLiteralDeclarationDescriptor(node: ts.InterfaceDeclaration, scope: Scope): ts.Expression { + const typeChecker: ts.TypeChecker = TypeChecker(); + const type: ts.Type = typeChecker.getTypeAtLocation(node); + + const properties: ts.Symbol[] = typeChecker.getPropertiesOfType(type); + const signatures: ReadonlyArray = type.getCallSignatures(); + + return GetMockPropertiesFromSymbol(properties, signatures, scope); +} diff --git a/test/transformer/descriptor/this/this.test.ts b/test/transformer/descriptor/this/this.test.ts index 0a6d6023f..86b175733 100644 --- a/test/transformer/descriptor/this/this.test.ts +++ b/test/transformer/descriptor/this/this.test.ts @@ -148,15 +148,17 @@ describe('This', () => { describe('for interface that contains a type literal', () => { interface BaseInterface { - getThis: this; + getThisBefore: this; typeLiteral: { a: string }; + getThisAfter: this; } it('should be able to reference to itself ', () => { const properties: BaseInterface = createMock(); expect(properties.typeLiteral.a).toBe(''); - expect(properties.getThis.typeLiteral.a).toBe(''); - expect(properties.getThis.getThis.getThis.typeLiteral.a).toBe(''); + expect(properties.getThisAfter.typeLiteral.a).toBe(''); + expect(properties.getThisBefore.typeLiteral.a).toBe(''); + expect(properties.getThisAfter.getThisBefore.getThisAfter.typeLiteral.a).toBe(''); }); }); });