@@ -883,11 +883,9 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam
883
883
case TypeSelector:
884
884
return " string" ;
885
885
case TypeCString: {
886
- std::string res = " string" ;
887
- if (isFuncParam) {
888
- Type typeVoid (TypeVoid);
889
- res += " | " + tsifyType (::Meta::PointerType (&typeVoid), isFuncParam);
890
- }
886
+ std::string res = isFuncParam ? " string | " : " " ;
887
+ Type typeVoid (TypeVoid);
888
+ res += tsifyType (::Meta::PointerType (&typeVoid), isFuncParam);
891
889
return res;
892
890
}
893
891
case TypeProtocol:
@@ -976,7 +974,26 @@ std::string DefinitionWriter::tsifyType(const Type& type, const bool isFuncParam
976
974
}
977
975
}
978
976
979
- if (interface.name == " NSArray" && isFuncParam) {
977
+ std::vector<std::string> protocols;
978
+ if (type.is (TypeType::TypeInterface) && type.as <InterfaceType>().protocols .size () > 0 ) {
979
+ for (auto & protocol : type.as <InterfaceType>().protocols ) {
980
+ if (protocol->jsName != " NSCopying" ) {
981
+ protocols.push_back (protocol->jsName );
982
+ }
983
+ }
984
+ }
985
+
986
+ if (protocols.size () > 0 ) {
987
+ // Example: -(NSObject<Option> *) getOption;
988
+ // Expected: getOption(): NSObject & Option;
989
+ for (auto & protocol : protocols) {
990
+ output << " & " << protocol;
991
+ }
992
+ } else if (interface.name == " NSArray" && isFuncParam) {
993
+ // In this case, NSArray<string> maps into NSArray<string> | string[]
994
+ // We only do this if there are no protocols, though
995
+ // for the very rare case where someone would do NSArray with a protocol
996
+ // as we can't marshal a JS array into NSArray + protocol
980
997
if (hasClosedGenerics) {
981
998
std::string arrayType = firstElementType;
982
999
output << " | " << arrayType << " []" ;
0 commit comments