title: TS-Record, XPath test, update Redux state, proxy pattern excerpt: In this blog post, I will be sharing a few tips and tricks that I have recently learned about TypeScript, XPath testing, updating Redux state, and the proxy pattern in JavaScript. These are all topics that I have found to be incredibly useful in my work and I hope that you will find them to be helpful as well.
coverImage: /assets/blog/ts-record_xpath-test_update-redux-state_proxy-pattern/cover.png coverImageInfo: Image generated by DALL-E2 coverImageUrl: https://openai.com/product/dall-e-2 date: "2023-03-16T07:45Z" source: https://adriankast.notion.site/TS-Record-XPath-test-update-Redux-state-proxy-pattern-25841fedd3254e7295e4f5f784a0cae4
In this blog post, I will be sharing a few tips and tricks that I have recently learned about TypeScript, XPath testing, updating Redux state, and the proxy pattern in JavaScript. These are all topics that I have found to be incredibly useful in my work and I hope that you will find them to be helpful as well. Let's dive in!
Using records in TypeScript can improve the readability of your types.
// do
type asdfT = Record<string, string>
// don't
type asdfT = {[k: string]: string}
// -----
// usage
const asdf: asdfT = { a: "value1", b: "value2"}
Records are available since TypeScript 2.1 and you can read more about them in the TS Doc on Record Type.
The TS-Record type maps keys of the first type to values of the second type, so remember they work a bit different than “Records” in some other programming languages.
In most modern browsers you can test XPath queries directly in the devtools. That means you can query the content of the website you have currently opened. XPath can often be handy e.g. for writing selectors in automated tests, when otherwise you don’t get some hard to query elements (for example with a CSS-Selector).
In Chrome querying XPath from the browser is as simple as $x('XpathQuery')
. So let’s say you want to get all div
elements, here you go: $x("//div")
.
Finding out about it has already saved me a lot of time.
This tip is a bit specific and mostly makes sense if you: