NativeScript / NativeScript/ios

Question on declarations generation

Aperta
#205 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
JavaScript
Stelle
150
Fork
43
Merge medio
3g 10h
PR unite (30g)
22

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da metadata-generator/src/TypeScript/DefinitionWriter.cpp intorno alla riga 862 e confronta la sua valutazione dei tipi con le dichiarazioni degli header Objective-C e l'ios.d.ts generato mostrato qui. Determina se è necessario modificare gli header di input oppure se il generatore perde i tipi dei protocolli; il completamento deve essere contrassegnato da una diagnosi chiara e dalla corretta conservazione dei tipi degli argomenti e di ritorno invece di NSObject.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, objective-c, typescript
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.