-
Typescript perfect sync – 3 tricks to keep it tight
Typescript perfect sync can be kept using couple of strategies. Most of us start with simple union types, like this: const ScenarioStatus = 'success' | 'fail' | 'error' | 'other'; So far so good. That works great… until you need to iterate over those values for rendering, validation, or other logic. And now You are stuck with two separate definitions: one array for logic, and one string union for the type. Sooner or later, they’ll fall out of sync and provide headaches to people. You could go for en enum…. Below behold the three TypeScript tricks to make your code tight, hard to break, cleaner, safer, DRYer and resistant to…
-
Typescript default parameters in constructor for GA
Typescript default parameters are the same as in scala. While working on multple google analytics projects it is good to now we can hardcode part of the object and then just use the simple, single object in a constructor, without having to pass the default values. However !! Typescript default parameters should be the last on the parameter list in constructor That said the not optional, required and demanded parameters need to be first. Otherwise intellij or what ever other ide You use might complain and will NOT TELL YOU THAT. I love that small little things You assume would be obvious but then You spend a lot of time…
-
Script setup Vue 3 – ❮Script lang=”ts” setup❯
Script setup <Script lang=”ts” setup> is something i really appreciate after migrating from vue 2. It is a part of the new Script Setup feature introduced in Vue 3. It replaces the traditional <script> block and provides a more concise and focused way to write components. The purpose of <script setup> is to simplify component code by removing unnecessary boilerplate and reducing redundancy. What Does It Do? The code inside <script setup> is compiled as the content of the component’s setup() function. You can remember it from vue 2 for both, composition and options api.Unlike the normal <script> block, which executed only once when the component is first imported, code…
-
Vite findByText to get all the elements
Vite findByText method could help us a lot, especially while testing any kind of i18n and similar. Of course we should always get the proepr component / element but such methods are very usefull when developing and debugging, later we can scrape it all. Later, when we know it works as we expect it. FindByText method can be especially usefull when we have a big flat table that may or may not be dynamically populated. Works great as a function to watch the vaues beeing present in the dom so we can catch the proper moment. Altough we could use the debugger, i find that printing a lot of stuff…










