-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Gutenboarding: Fix DomainSuggestionsQuery type #38219
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to just get them all with #38401
When thinking about it, extending this opens our type up for the application more than is desired. The type assertion in #38401 should leave our application with better safety and completion, and we can just tell the type system the type is fine (which it is).
*/ | ||
import { InputArgs } from '@wordpress/url'; | ||
|
||
export enum ActionType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, did we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be exported. Want to add it in #38401?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is being exported, just on a separate line. I can add the change to #38401 though.
I honestly don't know 🤷♂️ Without the changes in this PR, #38401 OTOH casts it to |
My thinking is that the most important part is for the type system to support us in writing a correct application. I believe the approach in #38401 deliver that better. interface I { [key: string]: string | undefined }
interface Bar { baz: string };
function foo(input: I) { }
const qux: Bar = { baz: 'foobarbazqux' }
// Nice completion, we know what the type is
const s: string = qux.baz
// This is an error, doesn't exist!
const s_ = qux.anythingAtAll
// The value contents are the same, but the type is different
const quux: I = {baz: 'foobarbazqux'}
// We don't know whether this exists or what it is because `I` is very open.
const t = quux.anythingAtAll
// Is this part helpful?
foo(qux) // Type error - we know it's fine but the type system isn't satisfied
foo(quux) // All good I think it's preferable to have a more restricted type in use throughout the application than it is to satisfy the parameter types. That's exactly what we get with the type assertion in #38401 - we tell the type system it's fine. |
Hmm right, that's a helpful example, thanks. It didn't occur to me that the index signature opened the interface up for basically any field, as long as it was compatible with it. Definitely something we should tighten. Alas, I'm still not a fan of ( queryObject as unknown ) as InputArgsObject To me, this reads like a very powerful cast (that could be basically applied to any type), no? ( 123 as unknown ) as InputArgsObject So while it expresses that we know that Can we somehow express that |
Accurate, this is the sledge hammer of the type system. It seems like the lesser concession and only affects us in one place.
I don't believe this is possible, the function signature requires that type. To the best of my understanding, anything narrowed-down will, by definition, not satisfy that type. I think this is an issue that should be addressed upstream in the type definition, or eventually right in Gutenberg, where they're adding types (WordPress/gutenberg#18838) and we're looking to generate type declarations from live code (WordPress/gutenberg#18942). |
Changes proposed in this Pull Request
Make
DomainSuggestionsQuery
extendInputArgs
in order to add an index signature,which we need for using
DomainSuggestionQuery
objects withaddQueryArgs
.This fixes one TS error.
Also simplify a type export while we're at it.
Testing instructions
should give one error less than on
master
.Also, verify that the app still builds and runs.