antd AutoComplete组件dataSource属性传入参数类型不匹配问题

typescript使用antd时,
websiteOptions赋值了一个调用map()方法的返回值,
在组件AutoComplete上使用是报错:
不能将类型“void[]”分配给类型“DataSourceItemType[] | undefined”。

这类应该是map()赋值给websiteOptions,类型时void[]
但是组件dataSource可的值的类型应该是DataSourceItemType[] || undefined
这里应该如何处理?

const websiteOptions = autoCompleteResult.map(website => {
            <AutoCompleteOption key={website}>{website}</AutoCompleteOption>
        })
     
     
    <AutoComplete 
        dataSource={ websiteOptions } // 不能将类型“void[]”分配给类型“DataSourceItemType[] | undefined”。
        onChange={this.handleWebsiteChange}
        placeholder="网址">
阅读 3.9k
2 个回答

已解决,const websiteOptions = autoCompleteResult.map(website => {

        <AutoCompleteOption key={website}>{website}</AutoCompleteOption>
    })
   应改成:
   const websiteOptions = autoCompleteResult.map(website => (
        <AutoCompleteOption key={website}>{website}</AutoCompleteOption>
    ))
    
    因为箭头函数没有默认return

试试Map出来以后单独做一个外层函数完成void[]DataSourceItemType[]的转换?