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

Missing Compiler API predicate functions: isImportTypeAssertionContainer #49306

Closed
5 tasks done
wessberg opened this issue May 30, 2022 · 1 comment · Fixed by #49313
Closed
5 tasks done

Missing Compiler API predicate functions: isImportTypeAssertionContainer #49306

wessberg opened this issue May 30, 2022 · 1 comment · Fixed by #49313
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@wessberg
Copy link

Search Terms

isImportTypeAssertionContainer

Suggestion

TypeScript's Compiler APIs include is functions for all kinds of Nodes. For example, isClassDeclaration, isBigIntLiteral, and so on.

In TypeScript 4.7 a new kind of node is introduced: ImportTypeAssertionContainer, but no isImportTypeAssertionContainer predicate function is exposed. For consistency with other kinds of Nodes, TypeScript should arguably also expose such a predicate function.

Use Cases

  • Custom Transformers (visiting and transforming Nodes in an AST)
  • Working with the Compiler APIs
  • etc

Examples

function visitNode (node: TS.Node, context: TS.TransformationContext, typescript: typeof TS): TS.VisitResult<TS.Node> {
    if (typescript.isImportTypeAssertionContainer(node) {
        return visitImportTypeAssertionContainer(node, context, typescript);
    }

    else if (...) {
        ....
    }
}

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.
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.7.3 milestone Jun 1, 2022
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript API Relates to the public API for TypeScript labels Jun 1, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jun 1, 2022
@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
3 participants