Open montemishkin opened 4 months ago
If I activate this option in the repo and run yarn test:tsc
, I get Found 66 errors in 35 files.
diff --git a/tsconfig.json b/tsconfig.json
index 668c98ef..7978fb37 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,6 +5,8 @@
"noImplicitAny": false,
"module": "Node16",
"baseUrl": "./src",
+ "exactOptionalPropertyTypes": true,
+ "strictNullChecks": true,
"paths": {
"@observablehq/plot": ["index"]
}
An alternative to adding | undefined
seems to be to declare the grouped types individually, rather than reading them from an optional field from another interface. For example one could do:
export type CurveAuto = Curve | "auto";
...
curve?: CurveAuto;
instead of
curve?: CurveAutoOptions["curve"];
(My point being, if we do change something here, we should not just make the errors go away, but rather fully embrace the stricter setting with stricter code?)
@Fil - Thanks for the quick turn around :)
58 of those 66 errors you mention are from the strictNullChecks
, whereas the remaining 8
are from the exactOptionalPropertyTypes
, which go away with the | undefined
addition.
For whatever reason, even though my repo using plot has strictNullChecks
enabled, I don't see the remaining 58 errors, where as I do see the 8
from exactOptionalPropertyTypes
.
If we want to address the strictNullChecks
errors, I'd suggest they happen in a different PR.
(For future reader context: if you just turn on exactOptionalPropertyTypes
, then typescript tells you you must also enable strictNullChecks
)
| undefined
vs "just copy-paste"I don't have a strong opinion here, but these are the pros / cons of the two approaches that I currently see:
| undefined
):
I'd stick with Option 1 personally, but there's a fair argument for either, and I don't have a strong opinion here. Got any consequences I'm not seeing / a stronger opinion than mine?
My suggestion (option 3 if you will) is to export a specific type (e.g. CurveAuto
) and to use it in all the places :-)
I don't see us doing only half the job. If we do support exactOptionalPropertyTypes
we probably want to activate it in the repo (so that it's helpful for us and we don't forget about it); this in turn requires strictNullChecks
too. It's a bit more work though.
Huh? What is this PR??
If a developer using plot with typescript has
exactOptionalPropertyTypes
turned on in their own project's tsconfig, then they will get 8 typescript errors from within plot's.d.ts
files. This PR adjusts plot's.d.ts
files to eliminate those errors.Other things to note
There should be no change to users who do not have that compiler option enabled. The plot repo itself does not have that compiler option enabled, and so also should not be affected, except by the unsightly / seemingly redundant
| undefined
I have added :/ It's a bit ugly, but given that this compiler option is recommended by typescript, seems worth supporting.Let me know if y'all have any questions / concerns. Thanks for the useful library!
The Errors
For reference, these are the errors that are eliminated by this PR: