-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
chore(ct): vue prop type of JsonObject #21400
Conversation
If we can only pass JsonObjects to props, the how are we supposed to test components that take things like functions or more complex objects as props? |
Vue works with events/emits instead of callbacks/functions as props. The What do you mean by complex objects? |
@sand4rt While the events/emits pattern is typical for Vue, it also does allow taking functions as props. I prefer to use functions as props because I find that it gives me more control through typing with typescript. You can only provide types for events/emits in Vue if you're using the <script setup> syntactic sugar. While it may not be the established best practice, I feel that a complete testing library for Vue should support it because Vue itself supports it. I can open an issue for further discussion if you'd like! As for more complex objects, I mean objects that may contain functions. For example, an instance of a class. |
I'd like to add my voice to reverse this change. You'll find that people cannot move from 1.31 to 1.32 because of this change specifically. I don't think it had the desired effect in terms of making code "safer"--this new restriction does not match what Vue considers good props. You really should let Vue decide what a bad prop is (and leave the type to |
@dospunk yeah sure, there are similar issues but i think it would be good to keep track of that! @unitydynamics could you provide an example that worked before the change and doesn't work after the change? |
@unitydynamics the example seem to work as expected, do I miss something?: interface MyType {
test: string;
}
const myTestProp = { test: 'hello' }
type JsonPrimitive = string | number | boolean | null;
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
type JsonArray = JsonValue[];
type JsonObject = { [Key in string]?: JsonValue };
const props: JsonObject = {
primitiveStringProp: 'works fine',
objectProp: { test: 'also works fine', test2: 4 }, // there was a missing comma here
interfaceProp: myTestProp, // doesn't type check!
} |
@sand4rt you're missing the type definition on myTestProp, line 4 should be const myTestProp: MyType = { test: 'hello' } |
You've simply removed Typescript from the relevant code. In your code So in my opinion, the 1.32 release didn't add anything to type safety of testing--but it made it much worse! |
@unitydynamics You need to Not sure if we should force @dospunk The problem of non-json serialisable data as props remains. This is a known issue, see related issues: #22003 (comment). |
Thanks for your consideration. I think understand why the props need to be Json serializable. For my part, I think throwing a runtime error is completely appropriate if a prop cannot be serialized. And personally I'm OK with that restriction (I don't need functions or vue refs or other non-data props) But please don't prohibit the use of Typescript interfaces! That would prevent most modern Vue developers from using playwright ct. |
@unitydynamics @dospunk thanks for sharing your thoughts! I've made a PR to revert the change. Let's wait for the Playwright team to respond: #22005. |
The
props
type has been changed so that code below throws a type error: