-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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.
danielpza, Gerrit0, dsebastien, vsetka, dmtrKovalenko and 11 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript