G6 icon indicating copy to clipboard operation
G6 copied to clipboard

TypeScript cannot compile with "strict: true"

Open BlackGlory opened this issue 3 years ago • 10 comments

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://repl.it/@BlackGlory/g6

Steps to reproduce

index.ts

import { Graph } from '@antv/g6'

package.json

{
  "scripts": {
    "build": "tsc --project tsconfig.json"
  },
  "dependencies": {
    "@antv/g6": "^4.1.6",
    "typescript": "^4.1.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020"
  , "module": "CommonJS"
  , "strict": true
  }
}
yarn build
Environment Info
g6 4.1.6
System -
Browser -

node_modules/@antv/g6-core/lib/graph/graph.d.ts:199:5 - error TS2416: Property 'updateBehavior' in type 'AbstractGraph' is not assignable to the same property in base type 'IAbstractGraph'.
  Type '(behavior: string, newCfg: object, mode?: string | undefined) => AbstractGraph' is not assignable to type '(behavior: string, newCfg: object, modes: string | string[]) => AbstractGraph'.
    Types of parameters 'mode' and 'modes' are incompatible.
      Type 'string | string[]' is not assignable to type 'string | undefined'.
        Type 'string[]' is not assignable to type 'string'.

199     updateBehavior(behavior: string, newCfg: object, mode?: string): AbstractGraph;
        ~~~~~~~~~~~~~~

node_modules/@antv/g6-core/lib/item/combo.d.ts:11:5 - error TS2416: Property 'getShapeCfg' in type 'Combo' is not assignable to the same property in base type 'ICombo'.
  Type '(model: ComboConfig) => ComboConfig' is not assignable to type '(model: ModelConfig) => ModelConfig'.
    Types of parameters 'model' and 'model' are incompatible.
      Property 'id' is missing in type 'ModelConfig' but required in type 'ComboConfig'.

11     getShapeCfg(model: ComboConfig): ComboConfig;
       ~~~~~~~~~~~

  node_modules/@antv/g6-core/lib/types/index.d.ts:407:5
    407     id: string;
            ~~
    'id' is declared here.

node_modules/@antv/g6-core/lib/item/combo.d.ts:66:5 - error TS2416: Property 'removeNode' in type 'Combo' is not assignable to the same property in base type 'ICombo'.
  Type '(node: INode) => boolean' is not assignable to type '(node: string | INode) => boolean'.
    Types of parameters 'node' and 'node' are incompatible.
      Type 'string | INode' is not assignable to type 'INode'.
        Type 'string' is not assignable to type 'INode'.

66     removeNode(node: INode): boolean;
       ~~~~~~~~~~

node_modules/@antv/g6-core/lib/item/node.d.ts:68:5 - error TS2416: Property 'isOnlyMove' in type 'Node' is not assignable to the same property in base type 'INode'.
  Type '(cfg: NodeConfig) => boolean' is not assignable to type '(cfg: ModelConfig) => boolean'.
    Types of parameters 'cfg' and 'cfg' are incompatible.
      Property 'id' is missing in type 'ModelConfig' but required in type 'NodeConfig'.

68     isOnlyMove(cfg: NodeConfig): boolean;
       ~~~~~~~~~~

  node_modules/@antv/g6-core/lib/types/index.d.ts:339:5
    339     id: string;
            ~~
    'id' is declared here.

node_modules/@antv/g6-pc/lib/graph/graph.d.ts:5:22 - error TS2420: Class 'Graph' incorrectly implements interface 'IGraph'.
  Types of property 'updateBehavior' are incompatible.
    Type '(behavior: string, newCfg: object, mode?: string | undefined) => AbstractGraph' is not assignable to type '(behavior: string, newCfg: object, modes: string | string[]) => AbstractGraph'.

5 export default class Graph extends AbstractGraph implements IGraph {
                       ~~~~~

node_modules/@antv/g6-pc/lib/graph/tree-graph.d.ts:4:22 - error TS2420: Class 'TreeGraph' incorrectly implements interface 'ITreeGraph'.
  Types of property 'updateBehavior' are incompatible.
    Type '(behavior: string, newCfg: object, mode?: string | undefined) => AbstractGraph' is not assignable to type '(behavior: string, newCfg: object, modes: string | string[]) => AbstractGraph'.

4 export default class TreeGraph extends Graph implements ITreeGraph {
                       ~~~~~~~~~


Found 6 errors.

BlackGlory avatar Jan 30 '21 04:01 BlackGlory

Try v4.1.7 pls

Yanyan-Wang avatar Jan 31 '21 08:01 Yanyan-Wang

@Yanyan-Wang

v4.1.7

node_modules/@antv/g6-core/lib/index.d.ts:1:23 - error TS2688: Cannot find type definition file for '[email protected]@gl-matrix'.

1 /// <reference types="[email protected]@gl-matrix" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@antv/g6-core/lib/util/index.d.ts:1:23 - error TS2688: Cannot find type definition file for '[email protected]@gl-matrix'.

1 /// <reference types="[email protected]@gl-matrix" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/graph/graph.d.ts:199:5 - error TS2416: Property 'updateBehavior' in type 'AbstractGraph' is not assignable to the same property in base type 'IAbstractGraph'.
  Type '(behavior: string, newCfg: object, mode?: string | undefined) => AbstractGraph' is not assignable to type '(behavior: string, newCfg: object, modes: string | string[]) => AbstractGraph'.
    Types of parameters 'mode' and 'modes' are incompatible.
      Type 'string | string[]' is not assignable to type 'string | undefined'.
        Type 'string[]' is not assignable to type 'string'.

199     updateBehavior(behavior: string, newCfg: object, mode?: string): AbstractGraph;
        ~~~~~~~~~~~~~~

node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/item/combo.d.ts:11:5 - error TS2416: Property 'getShapeCfg' in type 'Combo' is not assignable to the same property in base type 'ICombo'.
  Type '(model: ComboConfig) => ComboConfig' is not assignable to type '(model: ModelConfig) => ModelConfig'.
    Types of parameters 'model' and 'model' are incompatible.
      Property 'id' is missing in type 'ModelConfig' but required in type 'ComboConfig'.

11     getShapeCfg(model: ComboConfig): ComboConfig;
       ~~~~~~~~~~~

  node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/types/index.d.ts:407:5
    407     id: string;
            ~~
    'id' is declared here.

node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/item/combo.d.ts:66:5 - error TS2416: Property 'removeNode' in type 'Combo' is not assignable to the same property in base type 'ICombo'.
  Type '(node: INode) => boolean' is not assignable to type '(node: string | INode) => boolean'.
    Types of parameters 'node' and 'node' are incompatible.
      Type 'string | INode' is not assignable to type 'INode'.
        Type 'string' is not assignable to type 'INode'.

66     removeNode(node: INode): boolean;
       ~~~~~~~~~~

node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/item/node.d.ts:68:5 - error TS2416: Property 'isOnlyMove' in type 'Node' is not assignable to the same property in base type 'INode'.
  Type '(cfg: NodeConfig) => boolean' is not assignable to type '(cfg: ModelConfig) => boolean'.
    Types of parameters 'cfg' and 'cfg' are incompatible.
      Property 'id' is missing in type 'ModelConfig' but required in type 'NodeConfig'.

68     isOnlyMove(cfg: NodeConfig): boolean;
       ~~~~~~~~~~

  node_modules/@antv/g6-plugin/node_modules/@antv/g6-core/lib/types/index.d.ts:339:5
    339     id: string;
            ~~
    'id' is declared here.


Found 6 errors.

BlackGlory avatar Jan 31 '21 11:01 BlackGlory

What if configuring "skipLibCheck":true to ignore type checking of all declaration files (*.d.ts) for third libraries?

Yanyan-Wang avatar Feb 01 '21 02:02 Yanyan-Wang

@Yanyan-Wang That's unacceptable. skipLibCheck is used to shorten compilation time, not to ignore libraries with errors.

BlackGlory avatar Feb 01 '21 10:02 BlackGlory

getShapeCfg

pls check the version of @antv/core, it looks like that the core is not updated

Yanyan-Wang avatar Feb 02 '21 05:02 Yanyan-Wang

@Yanyan-Wang Please upgrade @antv/g6-plugin

+-- @antv/[email protected]
| `-- @antv/[email protected]
|   +-- @ant-design/[email protected]
|   | `-- [email protected]
|   +-- @antv/[email protected]
|   +-- @antv/[email protected]
|   | `-- [email protected]
|   +-- @antv/[email protected]
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected]
|   | | +-- @antv/[email protected] deduped
|   | | +-- [email protected] deduped
|   | | `-- [email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @types/[email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | | `-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- [email protected]
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- [email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected]
|   | | +-- [email protected]
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | `-- [email protected] deduped
|   | +-- @antv/[email protected]
|   | | +-- @antv/[email protected] deduped
|   | | +-- @webgpu/[email protected]
|   | | +-- @webgpu/[email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | +-- [email protected] deduped
|   | | `-- [email protected]
|   | +-- @webgpu/[email protected]
|   | +-- [email protected] deduped
|   | +-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | | `-- [email protected] deduped
|   | +-- [email protected]
|   | | `-- [email protected] deduped
|   | +-- [email protected]
|   | | +-- @babel/[email protected]
|   | | | `-- [email protected]
|   | | `-- @probe.gl/[email protected]
|   | |   `-- @babel/[email protected] deduped
|   | `-- [email protected]
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | `-- @antv/[email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected]
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected]
|   | | | +-- @antv/[email protected] deduped
|   | | | +-- [email protected] deduped
|   | | | `-- [email protected]
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | +-- @antv/[email protected] deduped
|   | | `-- [email protected] deduped
|   | +-- @antv/[email protected]
|   | | +-- @antv/[email protected] deduped
|   | | +-- [email protected] deduped
|   | | `-- [email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | +-- @antv/[email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | `-- @antv/[email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- [email protected] deduped
|   | +-- [email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- [email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | +-- @antv/[email protected] deduped
|   | +-- [email protected]
|   | `-- [email protected] deduped
|   +-- @antv/[email protected]
|   | `-- [email protected] deduped
|   +-- [email protected]
|   | +-- [email protected]
|   | | `-- [email protected]
|   | `-- [email protected]
|   |   +-- [email protected]
|   |   `-- [email protected]
|   |     `-- [email protected]
|   +-- [email protected]
|   | +-- [email protected]
|   | +-- [email protected]
|   | `-- [email protected]
|   +-- [email protected]
|   | +-- [email protected]
|   | | `-- [email protected] deduped
|   | `-- [email protected] deduped
|   +-- [email protected]
|   `-- [email protected]
|     `-- [email protected]
|       +-- [email protected]
|       | `-- [email protected]
|       |   +-- @types/[email protected]
|       |   +-- @types/[email protected]
|       |   `-- [email protected]
|       +-- [email protected]
|       | `-- [email protected] deduped
|       `-- [email protected]
|         `-- [email protected] deduped
`-- [email protected]

BlackGlory avatar Feb 02 '21 05:02 BlackGlory

Add "skipLibCheck": true, to tsconfig.json's compilerOptions can round this problem. But if you don't do that, Angular (version 11), G6 (version 4.25), and TypeScript (version 4.1.5) still have this problem.

Instead of skipping type checking with configuration items, you should fix this.

The error message

Error: node_modules/@antv/g6-core/lib/index.d.ts:1:23 - error TS2688: Cannot find type definition file for '[email protected]@gl-matrix'.

1 /// <reference types="[email protected]@gl-matrix" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~

Error: node_modules/@antv/g6-core/lib/util/index.d.ts:1:23 - error TS2688: Cannot find type definition file for '[email protected]@gl-matrix'.

1 /// <reference types="[email protected]@gl-matrix" />

billowstao avatar Apr 02 '21 04:04 billowstao

any news about that? g6 v.4.3.5 still facing this issue

plakyda-codefresh avatar Aug 09 '21 17:08 plakyda-codefresh

Failed to compile.

./node_modules/@antv/g6-core/lib/types/index.d.ts TypeScript error in ./node_modules/@antv/g6-core/lib/types/index.d.ts(24,37): Type expected. TS1110

22 | export declare type GraphTimingEvents = 'beforerender' | 'afterrender' | 'beforeadditem' | 'afteradditem' | 'beforeremoveitem' | 'afterremoveitem' | 'beforeupdateitem' | 'afterupdateitem' | 'beforeitemvisibilitychange' | 'afteritemvisibilitychange' | 'beforeitemstatechange' | 'afteritemstatechange' | 'beforeitemrefresh' | 'afteritemrefresh' | 'beforeitemstatesclear' | 'afteritemstatesclear' | 'beforemodechange' | 'aftermodechange' | 'beforelayout' | 'afterlayout' | 'beforegraphrefreshposition' | 'aftergraphrefreshposition' | 'beforegraphrefresh' | 'aftergraphrefresh' | 'beforeanimate' | 'afteranimate' | 'beforecreateedge' | 'aftercreateedge' | 'beforecollapseexpandcombo' | 'aftercollapseexpandcombo' | 'graphstatechange' | 'afteractivaterelations' | 'nodeselectChange' | 'itemcollapsed' | 'tooltipchange' | 'wheelzoom' | 'viewportchange' | 'dragnodeend' | 'stackchange' | 'beforepaint' | 'afterpaint';
23 | declare type MobileInteractionEvent = 'tap' | 'pinchstart' | 'pinmove' | 'panstart' | 'panmove' | 'panend';

24 | export declare type NodeEventType = node:${NodeInteractionEvent}; | ^ 25 | export declare type EdgeEventType = edge:${EdgeInteractionEvent}; 26 | export declare type ComboEventType = combo:${ComboInteractionEvent}; 27 | export declare type CanvasEventType = canvas:${CanvasInteractionEvent};

Lisa1787 avatar Mar 23 '22 08:03 Lisa1787

Failed to compile.

./node_modules/@antv/g6-core/lib/types/index.d.ts TypeScript error in ./node_modules/@antv/g6-core/lib/types/index.d.ts(24,37): Type expected. TS1110

22 | export declare type GraphTimingEvents = 'beforerender' | 'afterrender' | 'beforeadditem' | 'afteradditem' | 'beforeremoveitem' | 'afterremoveitem' | 'beforeupdateitem' | 'afterupdateitem' | 'beforeitemvisibilitychange' | 'afteritemvisibilitychange' | 'beforeitemstatechange' | 'afteritemstatechange' | 'beforeitemrefresh' | 'afteritemrefresh' | 'beforeitemstatesclear' | 'afteritemstatesclear' | 'beforemodechange' | 'aftermodechange' | 'beforelayout' | 'afterlayout' | 'beforegraphrefreshposition' | 'aftergraphrefreshposition' | 'beforegraphrefresh' | 'aftergraphrefresh' | 'beforeanimate' | 'afteranimate' | 'beforecreateedge' | 'aftercreateedge' | 'beforecollapseexpandcombo' | 'aftercollapseexpandcombo' | 'graphstatechange' | 'afteractivaterelations' | 'nodeselectChange' | 'itemcollapsed' | 'tooltipchange' | 'wheelzoom' | 'viewportchange' | 'dragnodeend' | 'stackchange' | 'beforepaint' | 'afterpaint';
23 | declare type MobileInteractionEvent = 'tap' | 'pinchstart' | 'pinmove' | 'panstart' | 'panmove' | 'panend';

24 | export declare type NodeEventType = node:${NodeInteractionEvent}; | ^ 25 | export declare type EdgeEventType = edge:${EdgeInteractionEvent}; 26 | export declare type ComboEventType = combo:${ComboInteractionEvent}; 27 | export declare type CanvasEventType = canvas:${CanvasInteractionEvent};

我也遇到了这个问题,请问你解决了嘛?

supuwoerc avatar Jun 06 '22 03:06 supuwoerc

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help. 这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

github-actions[bot] avatar Dec 08 '23 16:12 github-actions[bot]