NativeScript / NativeScript/ios

Question on declarations generation

Open
#205 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
150
Forks
43
Avg merge
3d 10h
Merged PRs (30d)
22

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with metadata-generator/src/TypeScript/DefinitionWriter.cpp around line 862 and compare its type evaluation with the Objective-C header declarations and generated ios.d.ts shown here. Determine whether the input headers need changes or whether the generator loses protocol types, with completion marked by a clear diagnosis and correctly preserved argument and return types instead of NSObject.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, objective-c, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.