NativeScript / ios

NativeScript for iOS and visionOS using V8
https://docs.nativescript.org/guide/ios-marshalling
131 stars 33 forks source link

feat: add protocol information to native types #247

Closed edusperoni closed 5 months ago

edusperoni commented 7 months ago

This is a possible breaking change

This adds additional information to native types that expect some kind of protocol.

Before:

@protocol Option                                                                                
-(NSString *) optionId;                                 
-(NSString *) type;                    
@end                                      
typedef NSObject<Option> Option; 

@protocol Info                                                                                 
-(NSArray<NSObject<Option> *> *) getOptions;
-(NSObject<Option> *) getOption;
@end
typedef NSObject<Info> Info;

Generated:

interface Option {                                      

        optionId(): string;                             

        type(): string;                                 
}                                                       
declare var Option: {                                   

        prototype: Option;                              
};

interface Info {

    getOption(): NSObject;          

        getOptions(): NSArray<NSObject>;

}                  
declare var Info: {       

        prototype: Info;          
};

After

interface Info {

    getOption(): NSObject & Option;

    getOptions(): NSArray<NSObject & Option>;
}
declare var Info: {

    prototype: Info;
};

interface Option {

    optionId(): string;

    type(): string;
}
declare var Option: {

    prototype: Option;
};

Possible breaking change

Types are a bit more strict, so anyone relying on the old types might get a compilation error after this.

Implements https://github.com/NativeScript/ios/issues/205

NathanWalker commented 6 months ago

On 8.8.0-alpha.0