Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set Style 'text-rotation' to 'autorotate' using Typescript? #2769

Closed
speatzle opened this issue Nov 6, 2020 · 3 comments
Closed

How to set Style 'text-rotation' to 'autorotate' using Typescript? #2769

speatzle opened this issue Nov 6, 2020 · 3 comments

Comments

@speatzle
Copy link

speatzle commented Nov 6, 2020

Issue type

Bug report

Environment info

  • Cytoscape.js version : 3.16.3
  • Browser/Node.js & version : v12.18.2

Current (buggy) behaviour

When using Typescript i am unable to set the styles 'text-rotation', 'source-text-rotation' and 'target-text-rotation' to the string 'autorotate' as described in the documentation under the point "Rotating text" because these only accept numbers as values.

Desired behaviour

Be able to use the autorotate feature when using Typescript.

Minimum steps to reproduce

  1. Make a Typescript project.
  2. Import Cytoscape,js
  3. Try Setting style 'text-rotation', 'source-text-rotation' or 'target-text-rotation' to 'autorotate'
  4. Try to Compile and get The Error: 'TS2322: Type 'string' is not assignable to type 'number | MapperFunction<EdgeSingular, number> | undefined'.'

Example Style:

import { Stylesheet } from 'cytoscape';
const cyStyle: Stylesheet[] = [{
  selector: 'edge',
  style: {
    label: 'Test Text',
    'text-rotation': 'autorotate',
  },
}]; 
@smith
Copy link

smith commented Nov 6, 2020

There are definitely some incorrect types (either out of date or that were always incorrect) in the DefinitelyTyped definitions. There are no type definitions in this repository or shipped with the cytoscape.js packages.

You can either open a PR on that repo to fix them or use @ts-expect-error in your code with an informative comment about the correct behavior.

The code should behave correctly even if the type checks fail.

@maxkfranz
Copy link
Member

See also #1012

@speatzle
Copy link
Author

speatzle commented Nov 9, 2020

I see. Thanks

@speatzle speatzle closed this as completed Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants