typescript-generator
typescript-generator copied to clipboard
NullableAnnotations other than CheckerFramework's @Nullable
This is similar to #889, but I couldn't find my answer there.
I am trying to generate a TS file from a bunch of Java classes through the typescript-generator-maven-plugin
.
The documentation states that I need to:
- tell the plugin which annotation(s) represent nullable fields, through the
<nullableAnnotations>
property - select how to represent nullability, through the
<nullabilityDefinition>
property
for example:
<nullableAnnotations>
<nullableAnnotation>my.own.annotation.Nullable</nullableAnnotation>
</nullableAnnotations>
<nullabilityDefinition>
nullAndUndefinedInlineUnion
</nullabilityDefinition>
- the documentation also specifies that the annotation must have target set to
TYPE_PARAMETER
orTYPE_USE
, and mentionsorg.checkerframework.checker.nullness.qual.Nullable
as an example of a suitable annotation for this purpose.
Indeed, if I use ChecherFramework's @Nullable
annotation, everything works fine.
export interface MyInterface {
id?: string;
booleanOrNull?: boolean | null;
}
This is ChecherFramework's @Nullable
annotation, for reference:
package org.checkerframework.checker.nullness.qual;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.checkerframework.framework.qual.DefaultFor;
import org.checkerframework.framework.qual.LiteralKind;
import org.checkerframework.framework.qual.QualifierForLiterals;
import org.checkerframework.framework.qual.SubtypeOf;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@SubtypeOf({})
@QualifierForLiterals({LiteralKind.NULL})
@DefaultFor(
types = {Void.class}
)
public @interface Nullable {
}
If instead I use my own annotation, copied one-to-one from ChecherFramework's @Nullable
annotation removing CF's own annotations, the feature stops working. This is my @Nullable
annotation:
package my.own.annotation;
import java.lang.annotation.*;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface Nullable {
}
and this is the output:
export interface MyInterface {
id?: string;
booleanOrNull?: boolean;
}
....sooooo what is it that org.checkerframework.checker.nullness.qual.Nullable
has, that my.own.annotation.Nullable
is missing in order to work? The only difference seems to be the additional annotations that come from CF's own package, but then is ChecherFramework's @Nullable
annotation the only annotation to be used for this feature?
Thanks, great tool anyway.