Fix bug where array element is undefined (#26433)

* Fix bug where array element is undefined

* Better fix
This commit is contained in:
Andy 2018-09-17 15:14:09 -07:00 committed by GitHub
parent a5326e68d0
commit bc709a87ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3470,8 +3470,8 @@ namespace ts {
const arity = getTypeReferenceArity(type);
const tupleConstituentNodes = mapToTypeNodes(typeArguments.slice(0, arity), context);
const hasRestElement = (<TupleType>type.target).hasRestElement;
if (tupleConstituentNodes && tupleConstituentNodes.length > 0) {
for (let i = (<TupleType>type.target).minLength; i < arity; i++) {
if (tupleConstituentNodes) {
for (let i = (<TupleType>type.target).minLength; i < Math.min(arity, tupleConstituentNodes.length); i++) {
tupleConstituentNodes[i] = hasRestElement && i === arity - 1 ?
createRestTypeNode(createArrayTypeNode(tupleConstituentNodes[i])) :
createOptionalTypeNode(tupleConstituentNodes[i]);