Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand the header flag in the JS Backend to produce a d.ts file. #552

Open
jmgomez opened this issue May 11, 2024 · 2 comments
Open

Expand the header flag in the JS Backend to produce a d.ts file. #552

jmgomez opened this issue May 11, 2024 · 2 comments

Comments

@jmgomez
Copy link

jmgomez commented May 11, 2024

Abstract

By leveraging on the existing mechanisms in the compiler, produce a d.ts file when the header flag is used. This file will be a header containing all the definitions exported in the Nim code. Just like the existing header works for the C/C++ backends.

Motivation

No response

Description

The main motivation is to improve the ergonomics of js/ts interop by providing type information that IDEs can use.

Code Examples

type 
  UserProfile*  {.exportc.} = object
    id* : int
    firstName*, lastName*, email*, phone*, country*, pictureUrl* : cstring
    
    proc createDefaultUserProfile*(): UserProfile {.exportc.} =
        UserProfile()

    proc getFullname*(profile: UserProfile): cstring {.exportc.} =    
        formatFullName(profile)
            

Would produce:

export declare type UserProfile = {
	id : number;
	firstName : string;
	lastName : string;
	email : string;
	phone : string;
	country : string;
	pictureUrl : string;
};

export declare function createDefaultUserProfile(): UserProfile;
export declare function getFullName(profile: UserProfile): string;

Backwards Compatibility

No response

@juancarlospaco
Copy link
Contributor

TS has become such a big target that it is worth supporting it somehow for the future of Nim.

@evelant
Copy link

evelant commented Jun 14, 2024

Would love to see this. I've got a large TS project and being able to write nim and have it "just work" without having to manually declare types would be amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants