gpt4 book ai didi

javascript - 如何正确地在函数中编写一个使流程满意的条件?

转载 作者:行者123 更新时间:2023-12-02 22:42:57 24 4
gpt4 key购买 nike

如何在函数中正确编写条件使流程满意?

我的函数应该能够处理 2 种不同的数据类型。

链接:https://flow.org/try/#0C4TwDgpgBAqgzhATgZQJYFswBtoF4oBQUUA3gD5HEDUAdgIboQBcUcwiqNA5gDSVRU4AV0QQAcg2at2nXpTIBfAgVCRYCFEMiJi+SuX7UaqAMYBrCYxZsO3PsUXLV0eEij5XKDNmhl1SZC0kAG5lAgAzIRoTYFQAexooLghgTwAKIQ0WTwBKUkpUcIyNADp6RjySSgBIUWARRMykEuFRSwhKBSgILAR84ig6hqgmxDLTC0lOgi6oIA

// @flow

type UserSimple = {|
+name: string,
+sureName: string,
|};

type UserSuper = {|
+nickName: string,
|};

type User = UserSimple | UserSuper;

function getUser(user: User) {
if (user.name) {
return user.sureName;
}
return user.nickName;
}

enter image description here

最佳答案

关于javascript - 如何正确地在函数中编写一个使流程满意的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58529128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com