Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-4442: [JS] Add explicit type annotation to Chunked typeId getter #3538

Closed

Conversation

trxcllnt
Copy link
Contributor

@trxcllnt trxcllnt commented Jan 31, 2019

Closes https://issues.apache.org/jira/browse/ARROW-4442

Typescript is generating an overly broad type for the typeId property of the ChunkedVector class, leading to a type mismatch and failure to infer Chunked<T> is a Vector<T>:

let col: Vector<Utf8>;
col = new Chunked(new Utf8());
  ^
/*
Argument of type 'Chunked<Utf8>' is not assignable to parameter of type 'Vector<Utf8>'.
  Type 'Chunked<Utf8>' is not assignable to type 'Vector<Utf8>'.
    Types of property 'typeId' are incompatible.
      Type 'Type' is not assignable to type 'Type.Utf8'.
*/

The type being generated currently is:

    readonly typeId: import("../enum").Type;

but it should be:

    readonly typeId: T['TType'];

The fix is to add an explicit return annotation to the Chunked typeId getter. Unfortunately this only affects the generated typings (.d.ts files) and not the library source, so it's difficult to test. We can look into whether there are any flags to trigger stricter type checking of the compiled code in the unit tests, but I don't know any off the top of my head.

@wesm wesm closed this in b0ac234 Feb 4, 2019
xhochy pushed a commit that referenced this pull request Feb 8, 2019
Closes https://issues.apache.org/jira/browse/ARROW-4442

Typescript is generating an overly broad type for the `typeId` property of the ChunkedVector class, leading to a type mismatch and failure to infer `Chunked<T>` is a `Vector<T>`:

```ts
let col: Vector<Utf8>;
col = new Chunked(new Utf8());
  ^
/*
Argument of type 'Chunked<Utf8>' is not assignable to parameter of type 'Vector<Utf8>'.
  Type 'Chunked<Utf8>' is not assignable to type 'Vector<Utf8>'.
    Types of property 'typeId' are incompatible.
      Type 'Type' is not assignable to type 'Type.Utf8'.
*/
```

The type being generated currently is:
```ts
    readonly typeId: import("../enum").Type;
```

but it should be:
```ts
    readonly typeId: T['TType'];
```

The fix is to add an explicit return annotation to the Chunked `typeId` getter. Unfortunately this only affects the generated typings (`.d.ts` files) and not the library source, so it's difficult to test. We can look into whether there are any flags to trigger stricter type checking of the compiled code in the unit tests, but I don't know any off the top of my head.

Author: ptaylor <paul.e.taylor@me.com>

Closes #3538 from trxcllnt/js/add-chunked-typeId-annoation and squashes the following commits:

077f383 <ptaylor> add explicit type annotation to Chunked typeId getter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants