feat(compiler): generate type parameters for generic type references (#14104)

This commit is contained in:
Chuck Jazdzewski
2017-01-30 15:32:08 -08:00
committed by Miško Hevery
parent 1079b9381c
commit 69e14b500b
11 changed files with 118 additions and 32 deletions

View File

@ -27,6 +27,7 @@ class SimpleJsImportGenerator implements ImportResolver {
return importedUrlStr;
}
getImportAs(symbol: StaticSymbol): StaticSymbol { return null; }
getTypeArity(symbol: StaticSymbol): number /*|null*/ { return null; }
}
export function main() {

View File

@ -264,4 +264,5 @@ export class SimpleJsImportGenerator implements ImportResolver {
return importedUrlStr;
}
getImportAs(symbol: StaticSymbol): StaticSymbol { return null; }
getTypeArity(symbol: StaticSymbol): number /*|null*/ { return null; }
}

View File

@ -75,4 +75,5 @@ class StubReflectorHost implements StaticSymbolResolverHost {
class StubImportResolver extends ImportResolver {
fileNameToModuleName(importedFilePath: string, containingFilePath: string): string { return ''; }
getImportAs(symbol: StaticSymbol): StaticSymbol { return null; }
getTypeArity(symbol: StaticSymbol): number /*|null*/ { return null; }
}

View File

@ -28,6 +28,7 @@ class SimpleJsImportGenerator implements ImportResolver {
return importedUrlStr;
}
getImportAs(symbol: StaticSymbol): StaticSymbol { return null; }
getTypeArity(symbol: StaticSymbol): number /*|null*/ { return null; }
}
export function main() {
@ -429,11 +430,19 @@ export function main() {
});
it('should support expression types', () => {
expect(
emitStmt(o.variable('a').set(o.NULL_EXPR).toDeclStmt(o.expressionType(o.variable('b')))))
.toEqual('var a:b = (null as any);');
});
it('should support expressions with type parameters', () => {
expect(emitStmt(o.variable('a')
.set(o.NULL_EXPR)
.toDeclStmt(o.expressionType(
o.variable('b'), [o.expressionType(o.variable('c'))]))))
.toEqual('var a:b<c> = (null as any);');
.toDeclStmt(o.importType(externalModuleIdentifier, [o.STRING_TYPE]))))
.toEqual([
`import * as import0 from 'somePackage/someOtherPath';`,
`var a:import0.someExternalId<string> = (null as any);`
].join('\n'));
});
it('should support combined types', () => {