首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型'(d:{ value: number }) =>号码‘不能指定为'number’

类型'(d:{ value: number }) =>号码‘不能指定为'number’
EN

Stack Overflow用户
提问于 2020-04-04 15:28:03
回答 1查看 994关注 0票数 0

当代码工作时,类型检查程序会抱怨如何将该委托方法分配给属性.

属性fontSize期望类型为number。但是,它是一个转换,并且不知怎么地,有一个带有属性value的字体对象需要转换为number类型。

方法特征提取(对象的破坏?)从字体对象数组中设置value属性。价值的例子是97。

输入: fontObj => {.值}

代码语言:javascript
复制
const onload = () => {
  const dv = new DataSet.View().source(data);
  const range = dv.range('value');
  const [min, max] = range;
  dv.transform({
    type: 'tag-cloud',
    fields: ['name', 'value'],
    imageMask: this.imageMask,
    font: () => {return 'Verdana'},
    size: [w, h], // The width and height settings are best based on imageMask Make adjustments
    padding: 0,
    timeInterval: 5000, // max execute time
    rotate: 0,
    /* rotate() {
      return 0;
    }, */
    fontSize: (d: { value: number }) => {     // <---- issue here!
      console.log(d);
      const size = ((d.value - min) / (max - min)) ** 2;
      return size * (17.5 - 5) + 5;
    },
  });

类型检查程序报告错误:

类型'(d:{ value: number }) =>号码‘不能指定为'number’

当然,仅仅分配一个数字值就可以解决线型问题,但是这里的目标是将传入的字体大小值转换成一个合适的大小。如何做到这一点,并满足类型检查?

谢谢!

打字:

位置: node_modules > @antv > data-set > lib > transform >tag-Cloud.ts

代码语言:javascript
复制
    export interface Options {
        fields?: [string, string];
        font?(): string;
        fontSize?: number;
        rotate?: number;
        padding?: number;
        size?: [number, number];
        spiral?: 'archimedean' | 'archimedean' | 'rectangular';
        timeInterval?: number;
        imageMask?: HTMLImageElement;
    }
EN

回答 1

Stack Overflow用户

发布于 2020-04-04 16:05:07

感谢@bergi,你指出打字中有一个错误!

打字内容如下:

代码语言:javascript
复制
export interface Options {
    fields?: [string, string];
    font?(): string;
    fontSize?: number;          //  <---- the trouble!
    rotate?: number;
    padding?: number;
    size?: [number, number];
    spiral?: 'archimedean' | 'archimedean' | 'rectangular';
    timeInterval?: number;
    imageMask?: HTMLImageElement;
}

现在我要说的是:

代码语言:javascript
复制
export interface Options {
    fields?: [string, string];
    font?(): string;
    fontSize?({}): number;          //  <---- the fix!
    rotate?: number;
    padding?: number;
    size?: [number, number];
    spiral?: 'archimedean' | 'archimedean' | 'rectangular';
    timeInterval?: number;
    imageMask?: HTMLImageElement;
}

以及更改财产分配,来自:

代码语言:javascript
复制
    fontSize(d: { value: number }) {
      const size = ((d.value - min) / (max - min)) ** 2;
      return size * (17.5 - 5) + 5;
    },

至:

代码语言:javascript
复制
    fontSize: (d: { value: number }) => {
      const size = ((d.value - min) / (max - min)) ** 2;
      return size * (17.5 - 5) + 5;
    },

看起来我需要看看是否有一个未解决的bug修复或者文件请求..。

tag-cloud.ts

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61030410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档