-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Improve each template literal infer #14920
Changes from all commits
9969aed
f4f8533
bdf450c
b4af639
fcc5d18
acf875e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,8 +217,8 @@ expectType<void>( | |
${'a'} | ${true} | ||
${'b'} | ${false} | ||
`('some test', ({item, expected}) => { | ||
expectType<unknown>(item); | ||
expectType<unknown>(expected); | ||
expectType<string | boolean>(item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm.. to be honest I find this behaviour confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I see what you mean. Not sure if there is a standard & this might ultimately be opinion. To clarify my reasoning, there are 2 advantages to using a union imo:
test.each`
a | expected
${0} | ${'0'}
${true} | ${'true'}
${'a'} | ${'a'}
`('strange stringify', ({a, expected}) => {
expect(toString(a)).toBe(expected); // no need to cast `a` here with union
});
test.each`
a | b | expected
${1} | ${2} | ${'three'}
${3} | ${4} | ${'seven'}
`('strange stringify', ({a, expected}) => {
const shouldError = expected as any[]
// With `unknown`: no error 😬
// With union: Conversion of type 'string | number' to type 'any[]' may be a mistake because neither type sufficiently overlaps with the other.
}); wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the proposal, but I don’t see it as improvement. Wrong types are wrong types (; This is only an opinion. I cannot merge PRs in this repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's an improvement to say "this can be a union of these types" over |
||
expectType<string | boolean>(expected); | ||
}), | ||
); | ||
expectType<void>( | ||
|
@@ -257,8 +257,8 @@ expectType<void>( | |
`( | ||
'some test', | ||
({item, expected}) => { | ||
expectType<unknown>(item); | ||
expectType<unknown>(expected); | ||
expectType<string | boolean>(item); | ||
expectType<string | boolean>(expected); | ||
}, | ||
1000, | ||
), | ||
|
@@ -393,8 +393,8 @@ expectType<void>( | |
${'a'} | ${true} | ||
${'b'} | ${false} | ||
`('some test', async ({item, expected}) => { | ||
expectType<unknown>(item); | ||
expectType<unknown>(expected); | ||
expectType<string | boolean>(item); | ||
expectType<string | boolean>(expected); | ||
}), | ||
); | ||
expectType<void>( | ||
|
@@ -432,8 +432,8 @@ expectType<void>( | |
`( | ||
'some test', | ||
({item, expected}) => { | ||
expectType<unknown>(item); | ||
expectType<unknown>(expected); | ||
expectType<string | boolean>(item); | ||
expectType<string | boolean>(expected); | ||
}, | ||
1000, | ||
), | ||
|
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.
The idea here was to start with a simple and correctly working example.
I find it strange showing how something does not work. If a feature does not work, why it is shipped? Just remove it.
It is just an option, but I think documentation should show how to use a library instead of focussing on what does not work.
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.
Also your change makes this feature work better. Why to say something does not work? Hey, look! This works like a charm. Use it!
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'm not sure what part you're referring to but I simplified it!
If case you were talking about the last part (2nd commit), I chose to leave it here, but more as a pitfall. wdyt?