Type annotations for tuples?

29 views
Skip to first unread message

Richard Connamacher

unread,
Feb 2, 2023, 12:48:20 PM2/2/23
to Closure Compiler Discuss
Does Closure Compiler have any syntax for type checking tuples (arrays with specific values at specific indexes) as used by Object.entries(), Object.fromEntries(), and popular libraries like React? On a hunch I tried using a record type with numerical indexes, but that's not understood as equivalent to an array/iterable:

/** @returns {{0: !number, 1: !string}} */
function getTuple() {
  return [99, "bottles of beer"];
}

JSC_TYPE_MISMATCH: inconsistent return type found : Array<?> required: { 0: number, 1: string } 

Thanks!
Richard

Anna Sidorova

unread,
Feb 6, 2023, 7:28:31 AM2/6/23
to Closure Compiler Discuss
Reply all
Reply to author
Forward
0 new messages