Skip to content

Instantly share code, notes, and snippets.

@Kureev
Created June 3, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kureev/f94b68d56e8392ff8df7ef683ffebbf7 to your computer and use it in GitHub Desktop.
Save Kureev/f94b68d56e8392ff8df7ef683ffebbf7 to your computer and use it in GitHub Desktop.
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,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment