Skip to content

AstBuilder methods which take an Option accept None without type annotation #5736

@overlookmotel

Description

@overlookmotel

Came across this in #4884:

let id = ctx.ast.binding_pattern(id, None::<TSTypeAnnotation<'_>>, false);

And also:

let id =
self.ast.binding_pattern::<Option<TSTypeAnnotation>>(binding_kind, None, false);

Is there any way to avoid need for type annotations when the param is None?

I tried changing binding_pattern to:

pub fn binding_pattern<T1>(
    self,
    kind: BindingPatternKind<'a>,
    type_annotation: Option<T1>,
    optional: bool,
) -> BindingPattern<'a>
where
    T1: IntoIn<'a, Box<'a, TSTypeAnnotation<'a>>>,
{
    BindingPattern {
        kind,
        type_annotation: type_annotation.map(|it| it.into_in(self.allocator)),
        optional
    }
}

But that doesn't help.

Is there anything we can do to avoid the need for type annotation on None?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions