Skip to content

Instantly share code, notes, and snippets.

@Kureev
Created June 3, 2019 20:24
Show Gist options
  • Select an option

  • Save Kureev/f94b68d56e8392ff8df7ef683ffebbf7 to your computer and use it in GitHub Desktop.

Select an option

Save Kureev/f94b68d56e8392ff8df7ef683ffebbf7 to your computer and use it in GitHub Desktop.

Revisions

  1. Kureev created this gist Jun 3, 2019.
    37 changes: 37 additions & 0 deletions parser-part.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    if (ts.isFunctionTypeNode(typeNode)) {
    let argument: Schemify.TypeAnnotation;
    this.checker
    .getSignaturesOfType(type, ts.SignatureKind.Call)
    /**
    * At this moment, react-native doesn't support more than one argument
    * (Event) passed back from the native side, however the implementation
    * I wrote was designed to support multiple parameters (just in case).
    *
    * That said, I assume the "getParameters" to always return an array
    * of one element (unless the schema in react-native is changed).
    * Otherwise, the latter one will override the first one
    */
    .forEach(signature => {
    signature.getParameters().forEach(parameter => {
    const paramType = this.checker.getTypeOfSymbolAtLocation(
    parameter,
    this.sourceFile
    );

    let type: ts.Type;
    (<any>paramType).typeArguments.forEach((typeArgument: ts.Type) => {
    typeArgument.getSymbol().members.forEach((member: ts.Symbol) => {
    type = this.checker.getTypeOfSymbolAtLocation(
    member,
    member.valueDeclaration
    );
    });
    });
    argument = this.getTypeAnnotation(type);
    });
    });
    return {
    type: 'FunctionTypeAnnotation',
    argument,
    };
    }