打字稿类型无法分配给“符号”错误

时间:2020-04-18 13:49:59

标签: typescript

export type anchorPositionType = "middle" | "left" | "right" | "top" | "bottom" | customAnchorType;
export type customAnchorType = { rightness?: number; bottomness?: number };

const getAnchorOffset = (width:number, height:number): { [key in anchorPositionType]: customAnchorType } => // here 'anchorPositionType' getting the error Type 'customAnchorType' is not assignable to type 'symbol' and i don't understand why?
 {
   return {
     middle: { rightness: width * 0.5, bottomness: height * 0.5 },
     left: { rightness: 0, bottomness: height * 0.5 },
     right: { rightness: width, bottomness: height * 0.5 },
     top: { rightness: width * 0.5, bottomness: 0 },
     bottom: { rightness: width, bottomness: height * 0.5 }
   };
};

我不知道是什么问题。为什么函数签名处的anchorPositionType出现错误Type 'customAnchorType' is not assignable to type 'symbol'

0 个答案:

没有答案