feat: improved types #2547

Merged
konrad merged 17 commits from dpschen/frontend:feature/improved-types into main 2022-11-02 16:06:57 +00:00
Member

This is a collection of unrelated type improvements that started growing while I was working on other stuff.


I don't know why my local pnpm always wants to upgrade the pnpm lockfile to 5.4 / why the dependabot lockfile always stays at 5.3. Any idea?

This is a collection of unrelated type improvements that started growing while I was working on other stuff. ---- I don't know why my local pnpm always wants to upgrade the pnpm lockfile to 5.4 / why the dependabot lockfile always stays at 5.3. Any idea?
dpschen added the
changes requested
area/internal-code
labels 2022-10-16 17:48:47 +00:00
dpschen force-pushed feature/improved-types from 8ce5d0345c to 6888b19cf3 2022-10-16 23:51:00 +00:00 Compare
Member

Hi dpschen!

Thank you for creating a PR!

I've deployed the changes of this PR on a preview environment under this URL: https://2547-feature-improved-types--vikunja-frontend-preview.netlify.app

You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.

Have a nice day!

Beep boop, I'm a bot.

Hi dpschen! Thank you for creating a PR! I've deployed the changes of this PR on a preview environment under this URL: https://2547-feature-improved-types--vikunja-frontend-preview.netlify.app You can use this url to view the changes live and test them out. You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/. Have a nice day! > Beep boop, I'm a bot.
Owner

I don't know why my local pnpm always wants to upgrade the pnpm lockfile to 5.4 / why the dependabot lockfile always stays at 5.3. Any idea?

This might be caused by renovate using an outated pnpm version. I've just upgraded renovate so this should be fixed now.

> I don't know why my local pnpm always wants to upgrade the pnpm lockfile to 5.4 / why the dependabot lockfile always stays at 5.3. Any idea? This might be caused by renovate using an outated pnpm version. I've just upgraded renovate so this should be fixed now.
dpschen force-pushed feature/improved-types from 6888b19cf3 to ba218180a7 2022-10-17 13:56:41 +00:00 Compare
dpschen force-pushed feature/improved-types from ba218180a7 to a4f24631a9 2022-10-17 14:06:10 +00:00 Compare
dpschen reviewed 2022-10-19 09:02:26 +00:00
@ -1,1 +3,4 @@
<!-- just a normal link -->
<!-- a button it shall be -->
<!-- note that we only pass the click listener here -->
<template>
Author
Member

I had to change the way how the BaseButton works for better type support.
It's a bit more repeatition but also very clear now what happens I guess.

Intersting sidenote: I originally placed the comments above inline to the switching elements but the vue renderer had some problems with that. Something about the component being a fragment which it should not be since it has just one root node. But seems like if you add a comment additionally to the root node (in case of a if / else that we have here), the comment counts as a node of the component. That makes sense, but is not intuitive, since you normally don't count a comment as content and prevents you from making good comments where they should be :)

I had to change the way how the BaseButton works for better type support. It's a bit more repeatition but also very clear now what happens I guess. Intersting sidenote: I originally placed the comments above inline to the switching elements but the vue renderer had some problems with that. Something about the component being a fragment which it should not be since it has just one root node. But seems like if you add a comment additionally to the root node (in case of a `if / else` that we have here), the comment counts as a node of the component. That makes sense, but is not intuitive, since you normally don't count a comment as content and prevents you from making good comments where they should be :)
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-19 09:02:58 +00:00
@ -16,0 +46,4 @@
SUBMIT: 'submit',
} as const
export type BaseButtonTypes = typeof BASE_BUTTON_TYPES_MAP[keyof typeof BASE_BUTTON_TYPES_MAP] | undefined
Author
Member

We export the types in order to use them in inheriting components

We export the types in order to use them in inheriting components
dpschen reviewed 2022-10-19 09:06:34 +00:00
@ -53,2 +65,2 @@
rel?: string;
target?: string;
export interface BaseButtonProps extends HTMLAttributes {
type?: BaseButtonTypes
Author
Member

As of now I had to add all possible combinations.
I tried to change the props based on the type but vue wouldn't accept that.
It boils down to that fact that vue currently doesn't support dynamic component types.

It might be that with the latest vue-tsc changes this is possible again.
Stricly speaking right now this component allows impossible prop combinations, these should be validated and filtered. But I hoped that I could spare that effort and solve it instead by establishing common knowledge on how this component is supposed to be used.

As of now I had to add all possible combinations. I tried to change the props [based on the type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) but vue wouldn't accept that. It boils down to that fact that vue currently doesn't support dynamic component types. It might be that with the latest vue-tsc changes this is possible again. Stricly speaking right now this component allows impossible prop combinations, these should be validated and filtered. But I hoped that I could spare that effort and solve it instead by establishing common knowledge on how this component is supposed to be used.

I think that's fine. Invalid combinations will show up in PR reviews.

I think that's fine. Invalid combinations will show up in PR reviews.
dpschen marked this conversation as resolved
dpschen changed title from WIP: feat: improved types to feat: improved types 2022-10-20 09:11:25 +00:00
dpschen requested review from konrad 2022-10-20 09:11:30 +00:00
konrad was assigned by dpschen 2022-10-20 09:11:33 +00:00
dpschen reviewed 2022-10-20 09:13:04 +00:00
@ -65,2 +46,2 @@
const variantClass = computed(() => BUTTON_TYPES_MAP[props.variant])
// extending the props of the BaseButton
export interface ButtonProps extends BaseButtonProps {
Author
Member

By extending the BaseButtonProps we inherit them and get proper autocomplete! :)

By extending the BaseButtonProps we inherit them and get proper autocomplete! :)
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-20 09:14:35 +00:00
@ -4,3 +2,1 @@
v-bind="elementBindings"
:to="to"
class="dropdown-item">
<BaseButton class="dropdown-item">
Author
Member

By reusing the BaseButton the dropdown-item got much simpler :)

By reusing the BaseButton the dropdown-item got much simpler :)

Wow it really looks a lot simpler now.

Wow it really looks a lot simpler now.
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-20 09:15:14 +00:00
@ -25,3 +26,3 @@
defineProps({
triggerIcon: {
type: String,
type: String as PropType<IconProp>,
Author
Member

Using IconProp enables autocomplete for the icons props

Using `IconProp` enables autocomplete for the icons props
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-20 09:16:13 +00:00
@ -14,3 +14,3 @@
v-tooltip="tooltipText"
@click="changeSubscription"
:class="{'is-disabled': disabled}"
:disabled="disabled"
Author
Member

Since dropdown inherits from basebutton it automatically inherits props like disabled

Since dropdown inherits from basebutton it automatically inherits props like disabled
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-20 09:20:27 +00:00
@ -7,3 +7,3 @@
}
if ((typeof date === 'string' || date instanceof String) && !date.startsWith('0001')) {
if ((typeof date === 'string') && !date.startsWith('0001')) {
Author
Member

We should stop using String(). Regardless date strings normally come from toISOString() which produces a type string

We should stop using `String()`. Regardless date strings normally come from `toISOString()` which produces a type string

There might be cases though where a date string comes from the api and needs to be parsed here. (or at leat that was the reason why I added this function originally)

There might be cases though where a date string comes from the api and needs to be parsed here. (or at leat that was the reason why I added this function originally)
Author
Member

Unsure if we talk here about the same. I'm talking about the general use of String() to convert something to a string. Afaik we don't do that anywhere for the data that's coming from the api. We do use the parseDateOrNull function but it should would without the instanceof String. If you think it should stay, I'm happy to revert this change.

Unsure if we talk here about the same. I'm talking about the general use of `String()` to convert something to a string. Afaik we don't do that anywhere for the data that's coming from the api. We do use the `parseDateOrNull` function but it should would without the `instanceof String`. If you think it should stay, I'm happy to revert this change.
dpschen reviewed 2022-10-20 09:21:10 +00:00
@ -21,2 +21,4 @@
updated: Date
settings: IUserSettings
isLocalUser: boolean
Author
Member

Is it correct to add these properties? They seemed to be missing.

Is it correct to add these properties? They seemed to be missing.

yes, that's correct.

yes, that's correct.
dpschen marked this conversation as resolved
dpschen reviewed 2022-10-20 09:22:20 +00:00
@ -28,6 +28,9 @@ export default class UserModel extends AbstractModel<IUser> implements IUser {
updated: Date
settings: IUserSettings
isLocalUser: boolean // FIXME: what should this be
Author
Member

I assumed that the type here is boolean.

I assumed that the type here is boolean.

That's correct, same as in the interface.

That's correct, same as in the interface.
Author
Member

I removed the comment.

I removed the comment.
konrad marked this conversation as resolved
dpschen reviewed 2022-10-20 09:29:35 +00:00
@ -19,3 +19,3 @@
},
"vueCompilerOptions": {
"strictTemplates": true
// "strictTemplates": true
Author
Member

Unsure about this

Unsure about this
Author
Member

Biggest reason why I can't judge this: Even after the merge of this branch we still have so many type errors that I don't know which errors appear / disappear when I toggle this option.

Biggest reason why I can't judge this: Even after the merge of this branch we still have so many type errors that I don't know which errors appear / disappear when I toggle this option.

Is there any difference in the number of errors?

Is there any difference in the number of errors?
Author
Member

Without "strictTemplates": true (I guess the default is false ;) )

Found 917 errors in 154 files.

With "strictTemplates": true

Found 949 errors in 159 files.

As said: I do not know which errors these are. It might also be that some disappear while others emerge.

Without `"strictTemplates": true` (I guess the default is false ;) ) ``` Found 917 errors in 154 files. ``` With `"strictTemplates": true` ``` Found 949 errors in 159 files. ``` As said: I do not know which errors these are. It might also be that some disappear while others emerge.
konrad reviewed 2022-10-20 13:30:11 +00:00
@ -2,2 +7,2 @@
<component
:is="componentNodeName"
<div
v-if="disabled === true && (to !== undefined || href !== undefined)"

Are there any cases where it makes sense for this to be a div?

Are there any cases where it makes sense for this to be a div?
Author
Member

Yes.
Out of a semantic perspective a disabled button / link is not a button / link.

Yes. Out of a semantic perspective a disabled button / link is not a button / link.
@ -7,0 +24,4 @@
class="base-button"
rel="noreferrer noopener nofollow"
target="_blank"
ref="button"

This looks like it's missing the href attribute.

This looks like it's missing the `href` attribute.
Author
Member

Good catch! Fixed

Good catch! Fixed
dpschen marked this conversation as resolved
@ -16,2 +16,2 @@
open.value = !open.value
}
import {ref} from 'vue'
import {onClickOutside} from '@vueuse/core'

I wonder if we even need the helper function I built back in the day?

I wonder if we even need the helper function I built back in the day?
Author
Member

I already try to remove it piece by piece :)

I already try to remove it piece by piece :)
dpschen marked this conversation as resolved
@ -0,0 +1,40 @@
// copied and slightly modified from unmerged pull request that corrects types
// https://github.com/FortAwesome/vue-fontawesome/pull/355

We need a reminder to remove this once the PR is merged (is that even possible entirely?)

We need a reminder to remove this once the PR is merged (is that even possible entirely?)
Author
Member

I subscribed to the thread of that PR. So I should get a notification if there are any changes.

I subscribed to the thread of that PR. So I should get a notification if there are any changes.
konrad marked this conversation as resolved
Author
Member

Anything blocking this?

Anything blocking this?
Owner

Anything blocking this?

Now that the gantt PR is merged there are conflicts :)

I'll do another review but I think we're good.

> Anything blocking this? Now that the gantt PR is merged there are conflicts :) I'll do another review but I think we're good.
Owner

Looks like the link button does not work :/

(For example when migrating from external services)

Looks like the link button does not work :/ (For example when migrating from external services)
dpschen force-pushed feature/improved-types from d2c153788b to 7f1100e819 2022-10-28 14:46:29 +00:00 Compare
Author
Member

Looks like the link button does not work :/

(For example when migrating from external services)

I think this was beacause of the missing href. Can't reproduce anymore, so should be solved.

> Looks like the link button does not work :/ > > (For example when migrating from external services) I think this was beacause of the missing `href`. Can't reproduce anymore, so should be solved.
dpschen force-pushed feature/improved-types from 87511139fe to 781dcb30d6 2022-10-31 18:24:44 +00:00 Compare
Author
Member

Can you check again?

Can you check again?
dpschen force-pushed feature/improved-types from 781dcb30d6 to 480aa8813e 2022-10-31 21:42:44 +00:00 Compare
dpschen added 2 commits 2022-11-01 12:13:07 +00:00
dpschen added 1 commit 2022-11-01 13:27:48 +00:00
continuous-integration/drone/pr Build is passing Details
e01df4d369
fix: coverImageAttachmentId
konrad approved these changes 2022-11-02 16:06:18 +00:00
konrad merged commit 0ff0d8c5b8 into main 2022-11-02 16:06:57 +00:00
konrad referenced this issue from a commit 2022-11-02 16:06:57 +00:00
konrad deleted branch feature/improved-types 2022-11-02 16:06:57 +00:00
This repo is archived. You cannot comment on pull requests.
No description provided.