Kaizen Today I Learned by Ville Säävuori

Posts tagged typescript

Ignoring Type Errors in Vue Templates

Sometimes you just need to work around type issues by using @ts-ignore or preferably @ts-expect-error. But what if the error shows up in your typed Vue template? Turns out Vue language tools gained a support doing exactly this not too long ago. You can use @vue-ignore and @vue-expect-error like so:

· Read the full article →

Converting Django Enumeration Types to TypeScript Enums

I added a UserEvent model to one of my personal projects as an excercise in learning about working with event-like data. One of the attributes is event_type which uses a Django models.IntegerChoices (could be models.TextChoices as well) class that looks like this: # models.py class UserEventType(models.IntegerChoices): ACCOUNT_CREATED = 100, "Account created" ACCOUNT_DELETED = 101, "Account deleted" PROFILE_UPDATED = 102, "Profile updated" PASSWORD_RESET_ASKED = 103, "Password reset asked" PASSWORD_RESET_DONE = 104, "Password reset done" PASSWORD_CHANGED = 105, "Password changed" LOGIN = 200, "Login" LOGOUT = 201, "Logout" MAIL_SUBSCRIBE = 401, "Mail subscribed" MAIL_UNSUBSCRIBE = 402, "Mail unsubscribed" I very quickly grew tired of trying to maintain the respective frontend TypeScript enums by hand so I wrote a quick & dirty management command that lets me copy paste full working code instead:

· Read the full article →

Typing Firebase Database Queries With TypeScript

Document databases like Firebase work great with JavaScript but they can get really messy really fast if you’re not very strict with your data models. TypeScript is the perfect companion here and luckily the Firebase database functions can be easily typed in a way that will help you to keep your data consistent.

· Read the full article →

Weeknotes 2022/22 - Re-learning Firebase

I first learned about Firebase bretty soon after it was initially launched. I first tested it myself for a small personal app few years ago but then migrated away from it mostly due to issues with the developer tooling and also because of the large payload for even a minimal client.

· Read the full article →

Narrowing unknown type in TypeScript

Type narrowing is one of the most useful and powerful features of TypeScript. Sometimes, however, it can be a bit too complicated. Consider this simple function that uses Firebase: export const useSignOut = async () => { try { const auth = getAuth() await signOut(auth) } catch (err: any) { alert(err.

· Read the full article →

My Recommended JS/TS Packages - Alleviate Choice Paralysis

One of the challenges of the JS ecosystem is the outrageous number of available packages. This is a continuously maintained list of useful and preferred JavaScript/TypeScript packages that I have personally worked with. A recommended package on this list has to have: Good documentation Healthy maintenance status Modern codebase (ie. support for treeshaking etc.

· Read the full article →