question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

is out-of-bounds in tuple of length,but the introduction in the document can be out of bounds

See original GitHub issue

TypeScript Version: 3.2.0 Code This is the official demo

// Declare a tuple type
let x: [string, number];
// Actually,this code will throw error
x[3] = 'world'; // OK, 'string' can be assigned to 'string | number'

Expected behavior: I want to know if this is a bug or this is document error

Actual behavior: Tuple out of bounds will trow error, but document say When accessing an element outside the set of known indices, a union type is used instead

Playground Link: https://www.tslang.cn/play/index.html#src=let x%3A [string%2C number]%3B %2F%2F When accessing an element outside the set of known indices%2C a union type is used instead%3A %2F%2F Actually,this code will throw error x[3] %3D “world”%3B %2F%2F OK%2C ‘string’ can be assigned to ‘string | number’

image

Related Issues: NO

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
weswighamcommented, Dec 7, 2018

Aye, the docs are out of date - I think tuples became fixed length around TS 2.5.

2reactions
xuniaojicommented, May 4, 2019

should fix that obvious mistake

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tuple index out of bounds - Stack Overflow
I am trying to use Recursive Templates for calculating the sum of elements in a tuple. But i keep running into an error...
Read more >
Understanding Tuples in Python 3 | DigitalOcean
Introduction. A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of elements. Because tuples are immutable, ...
Read more >
indexerror: Single positional indexer is out-of-bounds Error
When we deal with compound data types like lists and tuples or data sets having rows and columns in data science, we frequently...
Read more >
Tuple Objects — Python 3.11.1 documentation
Return true if p is a tuple object, but not an instance of a subtype of the tuple ... If pos is negative...
Read more >
Solidity Documentation - Read the Docs
but they can be efficiently accessed from outside the blockchain. Since some part of the log data is stored in bloom.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found