Enforce explicit function return type annotations?

前端 未结 1 1367
迷失自我
迷失自我 2021-01-29 11:19

I want to disable the ability to use \"any\" in typescript. For example, I have the following function

func() {
   return true
}

i want to requ

相关标签:
1条回答
  • 2021-01-29 11:26

    No, Function return types are inferred in typescript. The compiler itself has no setting to turn off type inference on functions. This feature was requested and decline as discussed in this issue filed on the typescript repository.

    However, your favourite lint tool can warn you when there is no type definition specified for a function. For completeness, I will provide this information.

    tslint

    The rule is called typedef. Add the following line to your tslint config

    "typedef": [ true, "call-signature", "arrow-call-signature" ]
    

    eslint

    The typescript-eslint plugin has this rule called explicit-function-return-type. (I cannot provide configuration instructions as I do not use eslint. Anyone is welcome to edit it in)

    0 讨论(0)
提交回复
热议问题