def METHOD_NAME(typ):
    typ = typ.replace(' ', '')
    type_map = {
        "()": "void",
        "&[u8]": "Buffer",
        "i32": "number",
        "u8": "number",
        "u32": "number",
        "u64": "Buffer",  # FIXME: eventually this should be a bigint
        "bool": "boolean",
        "String": "string",
        "&str": "string",
        "Vec<u8>": "Buffer",
        "ServiceId": "Buffer",
        "Aci": "Buffer",
        "Pni": "Buffer",
    }
    if typ in type_map:
        return type_map[typ]
    if typ.startswith('[u8;') or typ.startswith('&[u8;'):
        return 'Buffer'
    if typ.startswith('&mutdyn'):
        return typ[7:]
    if typ.startswith('&mut'):
        return 'Wrapper<' + typ[4:] + '>'
    if typ.startswith('&[&'):
        assert typ.endswith(']')
        return 'Wrapper<' + METHOD_NAME(typ[3:-1]) + '>[]'
    if typ.startswith('&['):
        assert typ.endswith(']')
        return 'Wrapper<' + METHOD_NAME(typ[2:-1]) + '>[]'
    if typ.startswith('&'):
        return 'Wrapper<' + typ[1:] + '>'
    if typ.startswith('Option<'):
        assert typ.endswith('>')
        return METHOD_NAME(typ[7:-1]) + ' | null'
    if typ.startswith('Result<'):
        assert typ.endswith('>')
        if ',' in typ:
            success_type = typ[7:].split(',')[0]
        else:
            success_type = typ[7:-1]
        return METHOD_NAME(success_type)
    if typ.startswith('Promise<'):
        assert typ.endswith('>')
        return 'Promise<' + METHOD_NAME(typ[8:-1]) + '>'
    return typ