如何从导入导出默认值?

时间:2019-09-25 15:34:49

标签: node.js typescript hapijs

使用以下内容将路由应用于hapi

如何重构export * from './foo';,以每条路由的默认导出替换*

routes / index.ts

'use strict';

export * from './foo'; // This is the line I’m trying to refactor

routes / foo.ts

'use strict';

import hapi from '@hapi/hapi';

const foo = [
  {
    method: 'POST',
    path: '/v1/clients/me',
    config: {
      ...
    },
    handler: async (request:hapi.Request, h:hapi.ResponseToolkit): Promise<hapi.ResponseObject> => {
      ...
    }
  },
];

export default foo;

这行得通,但要寻找单线。

'use strict';

import foo from './foo';
export const _foo = foo;

1 个答案:

答案 0 :(得分:0)

只要写

class MyClass(object):
    counter = 0

    def __init__(self):
        # other commands here

        # update id
        self.id = MyClass.counter
        MyClass.counter += 1

a,b = MyClass(), MyClass()

print(a.id, b.id)

# 0 1

`