Skip to content

Question on declarations generation #205

@legion151

Description

@legion151

Hello and thanks for your work.

I have a question regarding the generation of ios typescript declarations hoping to be in the right place.

We're using a robovm based toolchain to build a native library for iOS from Java-code. This toolchain emits header files in the following (shortened) form:

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

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

the (shortened) declarations in ios.d.ts are

interface Option {                                      
                                                        
        optionId(): string;                             
                                                        
        type(): string;                                 
}                                                       
declare var Option: {                                   
                                                        
        prototype: Option;                              
};

interface Info {
                                               
        getOptions(): NSArray<NSObject>;
                                           
}                  
declare var Info: {       
                                            
        prototype: Info;          
};

You may notice that the returned Array of getOptions is typed with NSObject instead of Option, which is the reason for this writing.

In fact are all argument- and return- types of functions which are defined by our headers typed with NSObject instead of the type which it should be.

After digging a while i understand that the types are evaluated in that function
https://github.com/NativeScript/ios/blob/main/metadata-generator/src/TypeScript/DefinitionWriter.cpp#L862
which might be wrong since it's been a while that i read some cpp code.

I assume that this codes falls back to NSObject if it cannot determine the correct type.
Note, that if i manually adjust the types in ios.d.ts everything works fine.

So basically my questions:

  • Are our input (the header files) missing something or do they have to be different soemhow to get beter outcomes?
  • If not would it be possible to patch the generator?
  • Am i totally wrong here?

Cheers and again thanks for your work.
legion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions