Generated TypeError messages show offending argument _value_, and perhaps better type identification
#127 创建于 2022年3月10日
仓库指标
- Star
- (78 star)
- PR 合并指标
- (PR 指标待抓取)
描述
Currently a typical type mismatch error looks like
TypeError: Unexpected type of argument.
Expected: number or boolean, actual: string, index: 1.
Would it be helpful to show the value of the argument at index 1 in the argument list as well? At least to the extent that something like
`${args[1]}`
would render it? I ask in part because the message is currently showing the "actual type" of the input argument, which can potentially be a little misleading as typed-function certainly allows overlapping types (i.e., there can be JavaScript entities for which more than one of the type test functions would return true, and this aspect is definitely used e.g. in mathjs). So perhaps as an additional enhancement it would be best for the "actual" type to show a union of all of the types whose tests return true on the actual argument? It's probably OK to take a little more processing time at this point since we're about to throw anyway... This latter bit would be an easy change to findTypeName, and looking at that led to finding a bug which I will file separately.