Skip to content

New error in 3.9: TS 7053 - can't index with number #38102

Closed
@amcasey

Description

@amcasey

TypeScript Version: 3.9.0-dev.20200420

Search Terms:

Intersection, Union, 7053

Code

export type TypedArray = Int32Array | Uint8Array;

export function isTypedArray(a: {}): a is Int32Array | Uint8Array {
  return a instanceof Int32Array || a instanceof Uint8Array;
}

export function flatten<T extends number|TypedArray>(arr: T) {
  if (isTypedArray(arr)) {
      arr[1]; // TS 7053
  }
}

3.8 behavior: No error
3.9 behavior: Error

Playground Link: https://www.typescriptlang.org/play/?ts=3.9.0-dev.20200420&ssl=1&ssc=1&pln=11&pc=2#code/KYDwDg9gTgLgBDAnmYcAqzgBMCCUoCGicAvHAJIB2MAzAEx6HEA+cAqgJbUAcjRA3AChBoSLDgAzAK6UAxjA4RKcDgGcMKXPiIAKAgC44AbwC+ASkMEVqitXp8W7LjF7biRwXDhRgMKVGUrLlUYAjlgCAlbWgY3OGZWIMoQsNkIqM4eByETYVFoeGk5BSVJABsCGBhgSgAeNDhQasosG0opAFsAI2AoZg1sBwA+PXxDNDNjTxUonTUBrSZRqDNJjy8NuAJ8AG0ARgBdIS9ckyA

Related Issues: I'm guessing this is another empty intersection bug, but I wasn't sure how to de-dup it.

Inspiration is from https://github.com/tensorflow/tfjs/blob/95995e7fec478e86b4baf0d34f902d3e345ee54b/tfjs-core/src/util.ts#L144

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions