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

[typings] Allow returning null from scriptable function #9665

Closed
ties-s opened this issue Sep 21, 2021 · 3 comments · Fixed by #9680
Closed

[typings] Allow returning null from scriptable function #9665

ties-s opened this issue Sep 21, 2021 · 3 comments · Fixed by #9680
Labels
type: bug type: types Typescript type changes
Milestone

Comments

@ties-s
Copy link

ties-s commented Sep 21, 2021

Expected Behavior

Should allow returning null from scriptable property functions like in example https://www.chartjs.org/docs/latest/samples/advanced/linear-gradient.html

Current Behavior

Type error

Type '(context: ScriptableContext<"line">, options: AnyObject) => Color | null' is not assignable to type 'string | _DeepPartialObject<CanvasGradient> | _DeepPartialObject<CanvasPattern> | ((ctx: ScriptableContext<"line">, options: AnyObject) => Color) | undefined'

Possible Solution

Change the type to also allow null

Steps to Reproduce

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENYBo4GUDGUwYM6ARgDYCmyEAdjFQB7wC+cAZlBCHAOT4MsAHQArAM58A3AFgAUPIBumOPhhM4AXjgATCPgCuIKg2EBzKjACi1YwwBCATwCSOgBQAiEI7SYYHgEpZOWUoOG9fWC04OioAdxQhGDc1JhwEeTgsuBhHMCoALn4KYFi+LEzsnXRSIoy5bMa4CnIqCnEigG0PACUqHQ8cD3sKAypBuA8ATTaKCDiJjwBxKCoTRYAFAygwakWAeSh0OgsPAF0Khqas6tJxSw64Tvrr65ayNqK+AGI4CA44AA1CCMSSXV5NW7oLoARgATDgYQBOHAAZhwAFYcAi4KiLpUIVkyOh8ABrMzcAx0HS0OZQIopeiMFhFAhEEjkai0BjMGAAHj4JTKAD4cBASMB6I9jo4AlphTEDBQKASmqwzqrWODsuKYJK6I8Xk1xPh0NRDarGkw6pamraslr7XBHDarhCnaxbZ63XBvawgkA

Context

Trying to implement the mentioned example in a TypeScript environment

Environment

  • Chart.js version: 3.5.1
  • Browser name and version: n/a (typescript compiler)
  • Link to your project:
@kurkle
Copy link
Member

kurkle commented Sep 21, 2021

I think the sample is actually flawed, it should return undefined, which is allowed.

@ties-s
Copy link
Author

ties-s commented Sep 21, 2021

Not really

Type 'undefined' is not assignable to type 'Color'.

@kurkle
Copy link
Member

kurkle commented Sep 21, 2021

Not really

Type 'undefined' is not assignable to type 'Color'.

Ok, definitely a problem in the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug type: types Typescript type changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants