import React from 'react';
import {
BasicLayoutProps,
Settings as LayoutSettings,
} from '@ant-design/pro-layout';
export const layout = ({
initialState,
}: {
initialState: { settings?: LayoutSettings; currentUser?: API.CurrentUser };
}): BasicLayoutProps => {
return {
rightContentRender: () => <RightContent />,
footerRender: () => <Footer />,
onPageChange: () => {
const { currentUser } = initialState;
const { location } = history;
// 如果没有登录,重定向到 login
if (!currentUser && location.pathname !== '/user/login') {
history.push('/user/login');
}
},
menuHeaderRender: undefined,
...initialState?.settings,
};
};
-------这里入参应该如何理解------
export const layout = ({
initialState,
}: {
initialState: { settings?: LayoutSettings; currentUser?: API.CurrentUser };
}): BasicLayoutProps => {
相当于没给参数命名而已。
简单一下翻译成JS应该是这样的
var layout = function (_a) {
var initialState = _a.initialState;
return;
};
TS和JS调用时一样layout({ initialState: { settings: .... } });
一般定义入参这样写:
export const layout = (initialState: Any): BasicLayoutProps => {
或
interface xxx{
}
export const layout = (initialState: xxx): BasicLayoutProps => {
上面这种定义参数类型叫啥写法或哪里有文档说明吗?google了一遍没有找到,谢谢
@wenbolwm: 确实这种做法比较少,但在TS中确实可行,你将其翻译为JS就是我说的这样。