Skip to content

Give some sentinel enums for Python cases translatable to TS types without counterpart #1

@guillaume-mueller

Description

@guillaume-mueller

Having to somewhat definitely choose to treat None as null or undefined seems not ideal in the long term.

Plus Python using None for functions not returning anything is not even compatible.

What about some explicit sentinel enums the user can give to py2ts.generate_ts for the TS types without Python counterparts such as unknown, void and undefined, in order to fluently makes them corresponds to the logic of the inspection flow.

This way one could for example do the following without having to treat special cases before calling py2ts.generate_ts:

def function(arg):
    ...

type_hints = get_type_hints(function)

arg_type_hint = type_hints.get('arg', py2ts.enums.unknown)
arg_ts_type = py2ts.generate_ts(arg_type_hint)

return_type_hint = type_hints.get('return', py2ts.enums.void)
return_ts_type = py2ts.generate_ts(return_type_hint)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions