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

Expose isArrayType, isTupleType, isArrayLikeType in TypeChecker #37711

Closed
5 tasks done
ayazhafiz opened this issue Mar 31, 2020 · 0 comments · Fixed by #52467
Closed
5 tasks done

Expose isArrayType, isTupleType, isArrayLikeType in TypeChecker #37711

ayazhafiz opened this issue Mar 31, 2020 · 0 comments · Fixed by #52467
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ayazhafiz
Copy link
Contributor

Search Terms

isArrayType, isTupleType, isArrayLikeType

Suggestion

Expose isArrayType, isTupleType, isArrayLikeType in the TypeChecker interfaace

Use Cases

Today, a consumer of the TypeScript compiler API must roll their own implementation of these functions (or call into a type checker's private API) to validate some type. It would be convenient if these functions were exposed publicly instead.

This is somewhat related to #9879 but is of a much smaller scope -- here we only wish to provide comparison methods for array-like and tuple types.

Examples

Current:

import * as ts from 'typescript';

function isArrayType(type: Type, checker: ts.TypeChecker): boolean {
  return (checker as any).isArrayType(type);
}

let ty: ts.Type = makeType();
if (isArrayType(ty)) {
  // do some array things
}

Suggested:

let ty: ts.Type = makeType();
let checker: ts.TypeChecker = getTypeChecker();
if (checker.isArrayType(ty)) {
  // do some array things
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants