diff --git a/src/type-translator.ts b/src/type-translator.ts index 648dbe44a..3a3814eca 100644 --- a/src/type-translator.ts +++ b/src/type-translator.ts @@ -306,6 +306,13 @@ export class TypeTranslator { // Emit the referenced type and any type arguments. let referenceType = type as ts.TypeReference; + // A tuple is a ReferenceType where the target is flagged Tuple and the + // typeArguments are the tuple arguments. Just treat it as a mystery + // array, because Closure doesn't understand tuples. + if (referenceType.target.objectFlags & ts.ObjectFlags.Tuple) { + return '!Array'; + } + let typeStr = ''; if (referenceType.target === referenceType) { // We get into an infinite loop here if the inner reference is diff --git a/test_files/type/type.js b/test_files/type/type.js index 0b89e83eb..dace07e4d 100644 --- a/test_files/type/type.js +++ b/test_files/type/type.js @@ -5,7 +5,11 @@ let /** @type {!Array>} */ typeNestedArr; let /** @type {{a: number, b: string}} */ typeObject = { a: 3, b: 'b' }; let /** @type {!Object} */ typeObject2; let /** @type {?} */ typeObject3; -let /** @type {!Object} */ typeObjectEmpty; +let /** @type {?} */ typeObjectEmpty; +let /** @type {!Array} */ typeTuple = [1, 2]; +let /** @type {!Array} */ typeComplexTuple = ['', true]; +let /** @type {!Array} */ typeTupleTuple = [[1, 2]]; +let /** @type {!Array} */ typeTupleTuple2 = [[1, 2], '']; let /** @type {(string|boolean)} */ typeUnion = Math.random() > 0.5 ? false : ''; let /** @type {(string|boolean)} */ typeUnion2 = Math.random() > 0.5 ? false : ''; let /** @type {{optional: (undefined|boolean)}} */ typeOptionalField = {}; diff --git a/test_files/type/type.ts b/test_files/type/type.ts index f14665221..357b88db3 100644 --- a/test_files/type/type.ts +++ b/test_files/type/type.ts @@ -8,11 +8,17 @@ let typeAny: any; let typeArr: Array; let typeArr2: any[]; let typeNestedArr: {a:any}[][]; + let typeObject: {a:number, b:string} = {a:3, b:'b'}; let typeObject2: {[key:string]: number}; let typeObject3: {a:number, [key:string]: number}; let typeObjectEmpty: {}; +let typeTuple: [number, number] = [1, 2]; +let typeComplexTuple: [string, true|{a:string}] = ['', true]; +let typeTupleTuple: [[number, number]] = [[1, 2]]; +let typeTupleTuple2: [[number, number], string] = [[1, 2], '']; + let typeUnion: string|boolean = Math.random() > 0.5 ? false : ''; let typeUnion2: (string|boolean) = Math.random() > 0.5 ? false : ''; let typeOptionalField: {optional?: boolean} = {}; diff --git a/test_files/type/type.tsickle.ts b/test_files/type/type.tsickle.ts index d6beacf34..a220a2e1e 100644 --- a/test_files/type/type.tsickle.ts +++ b/test_files/type/type.tsickle.ts @@ -1,6 +1,7 @@ -Warning at test_files/type/type.ts:13:5: unhandled type literal -Warning at test_files/type/type.ts:28:1: unhandled type {type flags:0x4000 TypeParameter symbol.name:"T"} -Warning at test_files/type/type.ts:28:1: unhandled type {type flags:0x4000 TypeParameter symbol.name:"T"} +Warning at test_files/type/type.ts:14:5: unhandled type literal +Warning at test_files/type/type.ts:15:5: symbol has no declarations +Warning at test_files/type/type.ts:34:1: unhandled type flags: TypeParameter +Warning at test_files/type/type.ts:34:1: unhandled type flags: TypeParameter ==== // Ensure we still understand what Array is, even when it has been // monkeypatched -- issue #170. @@ -12,10 +13,16 @@ let /** @type {?} */ typeAny: any; let /** @type {!Array} */ typeArr: Array; let /** @type {!Array} */ typeArr2: any[]; let /** @type {!Array>} */ typeNestedArr: {a:any}[][]; + let /** @type {{a: number, b: string}} */ typeObject: {a:number, b:string} = {a:3, b:'b'}; let /** @type {!Object} */ typeObject2: {[key:string]: number}; let /** @type {?} */ typeObject3: {a:number, [key:string]: number}; -let /** @type {!Object} */ typeObjectEmpty: {}; +let /** @type {?} */ typeObjectEmpty: {}; + +let /** @type {!Array} */ typeTuple: [number, number] = [1, 2]; +let /** @type {!Array} */ typeComplexTuple: [string, true|{a:string}] = ['', true]; +let /** @type {!Array} */ typeTupleTuple: [[number, number]] = [[1, 2]]; +let /** @type {!Array} */ typeTupleTuple2: [[number, number], string] = [[1, 2], '']; let /** @type {(string|boolean)} */ typeUnion: string|boolean = Math.random() > 0.5 ? false : ''; let /** @type {(string|boolean)} */ typeUnion2: (string|boolean) = Math.random() > 0.5 ? false : '';