Skip to content
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

Truncate long types #32

Merged
merged 4 commits into from
Jul 15, 2020
Merged

Conversation

osdiab
Copy link
Contributor

@osdiab osdiab commented Jun 18, 2020

Super long types in my app are pretty hard to read, this cuts them to 160 chars max.

Closes #2

@osdiab
Copy link
Contributor Author

osdiab commented Jun 18, 2020

Perhaps this behavior ought to be toggleable with a flag?

@@ -30,14 +30,18 @@ const getValidationContext = (validation: t.ValidationError) =>
// https://github.com/gcanti/fp-ts/pull/544/files
validation.context as t.ContextEntry[];

export const TYPE_MAX_LEN = 160; // Two lines of 80-col text
const truncateType = (type: string): string =>
type.length > TYPE_MAX_LEN ? `${type.slice(0, TYPE_MAX_LEN - 3)}...` : type;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to do the ... in the middle and show both the beginning and end, to make it feel more "complete"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would look better.

@@ -30,14 +30,18 @@ const getValidationContext = (validation: t.ValidationError) =>
// https://github.com/gcanti/fp-ts/pull/544/files
validation.context as t.ContextEntry[];

export const TYPE_MAX_LEN = 160; // Two lines of 80-col text
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an arbitrary number, perhaps it can be an overridable default

@osdiab
Copy link
Contributor Author

osdiab commented Jun 18, 2020

Can generally be smarter of how to do truncation like TypeScript is - but didn't implement that here. a lightly modified example of an error while developing:

Type '(params: {}, body: {}, ctx: ParameterizedContext<any, {}>) => Promise<{ status: number; message: string; data: { users: ({ entityName: EntityName.USER; } & { ...; })[]; comments: ({ ...; } & ... 2 more ... & { ...; })[]; }; }>' is not assignable to type '(params: {}, body: {}, ctx: ParameterizedContext<any, {}>) => Promise<ApiResponse<({ entityName: EntityName.COMMENT; } & { id: string; articleId: string; fromUserId: string; ... 5 more ...; text: string; })[]>>'.

Copy link
Owner

@gillchristian gillchristian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@gillchristian
Copy link
Owner

@osdiab Sorry, I merged a PR before yours and there are conflicts now 🤦 Once you fix them I'll merge and release

@osdiab
Copy link
Contributor Author

osdiab commented Jul 15, 2020

fixed!

@osdiab
Copy link
Contributor Author

osdiab commented Jul 15, 2020

Not sure what the version should be in the @since tag that Travis CI is worried about @gillchristian

@gillchristian
Copy link
Owner

Not sure what the version should be in the @since tag that Travis CI is worried about @gillchristian

Solved #32 (comment)

@gillchristian gillchristian merged commit 154cf03 into gillchristian:master Jul 15, 2020
@gillchristian
Copy link
Owner

Released v1.2.1. Thanks!

@lo1tuma
Copy link
Contributor

lo1tuma commented Jul 20, 2020

Seems like this is a breaking change shipped in a patch release. At least a lot of tests in my projects are failing due to this new default behavior. I’ll try to make a PR in the next days to provide an option to disable this behavior.

@gillchristian
Copy link
Owner

You are totally right, it should've been a major. Sorry for the inconvenience 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Truncate long values
3 participants