3 ms·
Not really https://github.com/microsoft/TypeScript/issues/9235 https://github.com/microsoft/TypeScript/issues/9235 Though with tuples, etc. being defined, mayb
by Eyas 7y ago
Not really https://github.com/microsoft/TypeScript/issues/9235 https://github.com/microsoft/TypeScript/issues/9235
Though with tuples, etc. being defined, maybe it's worth re-examining.
- seanwilson 7y agoThanks. Is there a pattern for array access that helps with my example? Is the only option to define your own safe access function like "function safeGetFromArray<T>(array: T, index:number): T | undefined"? I haven't tried it yet but it looks like the new optional element access feature is only checking if the array itself is defined, not if the array index is defined.
- emptysea 7y agoI can't seem the find the GitHub issue for it off hand, but I believe you can override the default indexing signature for arrays to return possibly undefined. Otherwise, you're left to creating a wrapper function and a custom ESlint rule. Edit: found it https://github.com/microsoft/TypeScript/issues/13778#issuecomment-277029664 https://github.com/microsoft/TypeScript/issues/13778#issueco... The suggestion is to maintain your own copy of `index.d.ts` with the array indexing interface modified. Yikes!