Skip to content

Commit 117aa37

Browse files
committed
feat: add protocol information to native types
1 parent 3294c4b commit 117aa37

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

metadata-generator/src/TypeScript/DefinitionWriter.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,26 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam
976976
}
977977
}
978978

979-
if (interface.name == "NSArray" && isFuncParam) {
979+
std::vector<std::string> protocols;
980+
if (type.is(TypeType::TypeInterface) && type.as<InterfaceType>().protocols.size() > 0) {
981+
for (auto & protocol : type.as<InterfaceType>().protocols) {
982+
if (protocol->jsName != "NSCopying") {
983+
protocols.push_back(protocol->jsName);
984+
}
985+
}
986+
}
987+
988+
if (protocols.size() > 0) {
989+
// Example: -(NSObject<Option> *) getOption;
990+
// Expected: getOption(): NSObject & Option;
991+
for (auto & protocol : protocols) {
992+
output << " & " << protocol;
993+
}
994+
} else if (interface.name == "NSArray" && isFuncParam) {
995+
// In this case, NSArray<string> maps into NSArray<string> | string[]
996+
// We only do this if there are no protocols, though
997+
// for the very rare case where someone would do NSArray with a protocol
998+
// as we can't marshal a JS array into NSArray + protocol
980999
if (hasClosedGenerics) {
9811000
std::string arrayType = firstElementType;
9821001
output << " | " << arrayType << "[]";

0 commit comments

Comments
 (0)