为什么要进行类型检查?

Why does it type check?

这个对我来说没有意义:

import axios from 'axios'
import * as TE from 'fp-ts/lib/TaskEither'

export const getIntent = (sessionId: string, input: string) => process.env.INTENT_URL
  ? TE.tryCatch(
      () => axios.post(`${process.env.INTENT_URL}`,{sessionId, input}),
      reason => String(reason))
  : TE.left(Error("No INTENT_URL")
)

Left就是Stringand/orError,显然不相等。这种类型检查怎么来的???

进行此类型检查的原因相同:

export const getIntent = () => process.env.INTENT_URL
  ? true
  : "false"

您的函数上没有 return 类型注释,因此打字稿会自动将 return 类型扩展为联合类型以涵盖 return 值。