-
-
Notifications
You must be signed in to change notification settings - Fork 4.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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment types of Flow makes Prettier confused #5446
Comments
Does upgrading to Prettier 1.15.2 fix the issue for you? |
@j-f1 Thanks for your comment! Also, I can reproduce it on v1.15.2 playground. 馃檹 Maybe playgroundPrettier 1.15.2 --jsx-bracket-same-line
--parser flow
--trailing-comma all Input: // @flow
const mapDispatch: MapDispatch<*> = (dispatch, props) => ({
...props,
onInit: ({ user }: { user: Some_user }) => {
if (user) {
const { name } = user;
switch (user.__typename) {
case "A": {
dispatch(user.onInitByQuery("A"));
break;
}
case "B":
dispatch(user.onInitByQuery("B"));
break;
case "C":
dispatch(user.onInitByQuery("C"));
break;
default:
/* :: (user.__typename: empty); */ // eslint-disable-line
break;
}
dispatch(
user.onInitByQuery({
user: { firstName: first_name, lastName: last_name },
}),
);
}
},
});
type Props = {|
...$Exact<PropsWithTFn>,
...$Exact<$Call<typeof mapStateToProps, *, *>>,
...$Exact<$Call<typeof mapDispatch, *, *>>,
...$Exact<withResponse.WithQueryProps<RootQuery>>,
|}; Output: // @flow
const mapDispatch: MapDispatch<*> = (dispatch, props) => ({
...props,
onInit: ({ user }: { user: Some_user }) => {
if (user) {
const { name } = user;
switch (user.__typename) {
case "A": {
dispatch(user.onInitByQuery("A"));
break;
}
case "B":
dispatch(user.onInitByQuery("B"));
break;
case "C":
dispatch(user.onInitByQuery("C"));
break;
default:
(user.__typename: empty); // eslint-disable-line
break;
}
dispatch(
user.onInitByQuery({
user: { firstName: first_name, lastName: last_name },
}),
);
}
},
});
type Props = {|
...$Exact/*:: <PropsWithTFn> */,
...$Exact/*:: <$Call/*:: <typeof mapStateToProps, *, *> */> */,
...$Exact/*:: <$Call/*:: <typeof mapDispatch, *, *> */> */,
...$Exact/*:: <withResponse.WithQueryProps/*:: <RootQuery> */> */,
|}; |
That鈥檚 a long-standing issue with the Flow parser. Using the default Prettier 1.15.2 --jsx-bracket-same-line
--parser babylon
--trailing-comma all Input: // @flow
const mapDispatch: MapDispatch<*> = (dispatch, props) => ({
...props,
onInit: ({ user }: { user: Some_user }) => {
if (user) {
const { name } = user;
switch (user.__typename) {
case "A": {
dispatch(user.onInitByQuery("A"));
break;
}
case "B":
dispatch(user.onInitByQuery("B"));
break;
case "C":
dispatch(user.onInitByQuery("C"));
break;
default:
/* :: (user.__typename: empty); */ // eslint-disable-line
break;
}
dispatch(
user.onInitByQuery({
user: { firstName: first_name, lastName: last_name },
}),
);
}
},
});
type Props = {|
...$Exact<PropsWithTFn>,
...$Exact<$Call<typeof mapStateToProps, *, *>>,
...$Exact<$Call<typeof mapDispatch, *, *>>,
...$Exact<withResponse.WithQueryProps<RootQuery>>,
|}; Output: // @flow
const mapDispatch: MapDispatch<*> = (dispatch, props) => ({
...props,
onInit: ({ user }: { user: Some_user }) => {
if (user) {
const { name } = user;
switch (user.__typename) {
case "A": {
dispatch(user.onInitByQuery("A"));
break;
}
case "B":
dispatch(user.onInitByQuery("B"));
break;
case "C":
dispatch(user.onInitByQuery("C"));
break;
default:
/* :: (user.__typename: empty); */ // eslint-disable-line
break;
}
dispatch(
user.onInitByQuery({
user: { firstName: first_name, lastName: last_name },
}),
);
}
},
});
type Props = {|
...$Exact<PropsWithTFn>,
...$Exact<$Call<typeof mapStateToProps, *, *>>,
...$Exact<$Call<typeof mapDispatch, *, *>>,
...$Exact<withResponse.WithQueryProps<RootQuery>>,
|}; |
@j-f1 There're two bugs in the example:
|
Ah, missed that. Apologies. |
Still occurred at FYI, I attempt to present the smallest reproduction codes here It's just from /* :: (kind: empty);*/
export const A: T<V> = 0; to (kind: empty);
export const A: T/*:: <V> */ = 0; I wonder although the issue labeld as a high-priority bug, but it still not fixed. |
Please go ahead! We appreciate PRs. |
Not an issue anymore because support for Flow comments was removed in #13687 |
@fisker Why did you reopen it? |
Sorry, must hit the wrong button. |
Prettier 1.15.1
Sorry, I could not reproduce it on v1.15.2 playground. 馃檱 (solved at 1.15.2 ? 馃憖)
Playground link
In flow, I can typecast with the following, not type-assertion.
Input:
However, this gets error message below in prettier 1.15.1
Output:
Expected behavior:
The text was updated successfully, but these errors were encountered: