-
Notifications
You must be signed in to change notification settings - Fork 31
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
Remove explicit null value from JSDOC type definition for domain values #141
Conversation
I spoke too soon, this does not fix the problem 🙈 |
Also didn't see the previous discussion in #117 |
Hm – it would seem fairly basic to me that something could be null. Is it saying that it needs to have both types be the same? Do you get the same error if you set |
Yes, seems to be the same error:
I fully agree, that something could be null seems fairly basic (and I like this as an easily understandable API). |
FWIW, having the error is due to |
Great find! So if we remove that and keep the JSDoc types as they are currently, that solves it? Or is it better to change the syntax as you describe above? |
I don't know. The problem occurs because the default of a new SvelteKit project with JSDoc/Typescript includes Thus it might be better to change the syntax. I'll need to test that, i am slowly wrapping my head around where things go and when to |
I think the leading There is no difference when they are left out: But maybe we rather want this, only the second parameter being nullable? The domains in the examples all seem to be When turning the example above in a little Test module I can import the component without problems and without any I found these links helpful: |
Got it I think, in LayerCake repo itself
/**
* @type {?number}
* With strictNullChecks: true -- number | null
* With strictNullChecks: false -- number
*/
var nullable; https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#unsupported-patterns One can see the difference in yDomain?: Function | string[] | number[] | [min: number, max: number | null] | undefined; Without yDomain?: Function | string[] | number[] | [min: number, max: number]; In the Remains the question, what is the desired configuration?
|
This led to the error message: Error: Type '[number, null]' is not assignable to type 'Function | number[] | string[] | [min: number, max: number] | undefined'. Type '[number, null]' is not assignable to type 'Function | number[] | string[] | [min: number, max: number]'. Type '[number, null]' is not assignable to type '[min: number, max: number]'. Type at position 1 in source is not compatible with type at position 1 in target. Type 'null' is not assignable to type 'number'. (js)
This should be the correct name, wrongly renamed in SHA: cfae9fa
c100ae5
to
d951e89
Compare
This should enable using nullable types, e.g. in domains. See mhkeller#141
[null, 0] could be used for data with negative minimum.
I switched to the In https://github.com/mhkeller/layercake/blob/main/src/lib/utils/partialDomain.js |
Wow thanks a bunch for diving in and doing all of this great research! I'll merge this and put it as a patch release, which I should be able to do later today. |
Thank you! Very glad to be able to give back a tiny bit to LayerCake, it's awesome! |
Are there any changes that should be made to the starter template https://github.com/mhkeller/layercake-template? |
This is published as 7.6.1! |
I thought about that, too. I'll take a look. |
When using Layercake in a SvelteKit project with JSDoc or TypeScript type checking I am getting an error message for the
[0, null]
domain values, for exampleyDomain
here:This gives the error message (from
npm run check
):When I change the JSDOC definitions to remove `|null' it still seems to work fine, so maybe there are not neccessary?
JSDoc.app lists nullable types like this as well
https://jsdoc.app/tags-type.html