Skip to content

Commit

Permalink
feat: add protocol information to native types
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni committed Jun 25, 2024
1 parent 6ec9a8f commit 1e0a8c6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion metadata-generator/src/TypeScript/DefinitionWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,26 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam
}
}

if (interface.name == "NSArray" && isFuncParam) {
std::vector<std::string> protocols;
if (type.is(TypeType::TypeInterface) && type.as<InterfaceType>().protocols.size() > 0) {
for (auto & protocol : type.as<InterfaceType>().protocols) {
if (protocol->jsName != "NSCopying") {
protocols.push_back(protocol->jsName);
}
}
}

if (protocols.size() > 0) {
// Example: -(NSObject<Option> *) getOption;
// Expected: getOption(): NSObject & Option;
for (auto & protocol : protocols) {
output << " & " << protocol;
}
} else if (interface.name == "NSArray" && isFuncParam) {
// In this case, NSArray<string> maps into NSArray<string> | string[]
// We only do this if there are no protocols, though
// for the very rare case where someone would do NSArray with a protocol
// as we can't marshal a JS array into NSArray + protocol
if (hasClosedGenerics) {
std::string arrayType = firstElementType;
output << " | " << arrayType << "[]";
Expand Down

0 comments on commit 1e0a8c6

Please sign in to comment.