diff --git a/src/compiler/transformers/test/parse-props.spec.ts b/src/compiler/transformers/test/parse-props.spec.ts index 1f3c987edb5..ac1830c884a 100644 --- a/src/compiler/transformers/test/parse-props.spec.ts +++ b/src/compiler/transformers/test/parse-props.spec.ts @@ -34,6 +34,39 @@ describe('parse props', () => { expect(t.cmp?.hasProp).toBe(true); }); + it('should correctly parse a prop with an unresolved type', () => { + const t = transpileModule(` + @Component({tag: 'cmp-a'}) + export class CmpA { + @Prop() val?: Foo; + } + `); + expect(getStaticGetter(t.outputText, 'properties')).toEqual({ + val: { + attribute: 'val', + complexType: { + references: { + Foo: { + id: 'global::Foo', + location: 'global', + }, + }, + resolved: 'Foo', + original: 'Foo', + }, + docs: { + text: '', + tags: [], + }, + mutable: false, + optional: true, + reflect: false, + required: false, + type: 'any', + }, + }); + }); + it('prop required', () => { const t = transpileModule(` @Component({tag: 'cmp-a'}) diff --git a/src/compiler/transformers/transform-utils.ts b/src/compiler/transformers/transform-utils.ts index 4a40987811a..68a30e8142b 100644 --- a/src/compiler/transformers/transform-utils.ts +++ b/src/compiler/transformers/transform-utils.ts @@ -519,18 +519,20 @@ const getTypeReferenceLocation = ( const compilerHost = ts.createCompilerHost(options); const importHomeModule = getHomeModule(sourceFile, localImportPath, options, compilerHost, program); - const importName = namedImportBindings.elements.find((nbe) => nbe.name.getText() === typeName).name; - const originalTypeName = getOriginalTypeName(importName, checker); - - const typeDecl = findTypeWithName(importHomeModule, originalTypeName); - type = checker.getTypeAtLocation(typeDecl); - - const id = addToLibrary(type, originalTypeName, checker, normalizePath(importHomeModule.fileName, false)); - return { - location: 'import', - path: localImportPath, - id, - }; + if (importHomeModule) { + const importName = namedImportBindings.elements.find((nbe) => nbe.name.getText() === typeName).name; + const originalTypeName = getOriginalTypeName(importName, checker); + + const typeDecl = findTypeWithName(importHomeModule, originalTypeName); + type = checker.getTypeAtLocation(typeDecl); + + const id = addToLibrary(type, originalTypeName, checker, normalizePath(importHomeModule.fileName, false)); + return { + location: 'import', + path: localImportPath, + id, + }; + } } // Loop through all top level exports to find if any reference to the type for 'local' reference location