In this article, I will walk you through a step-by-step guide to building your first LLM-powered application using LangChain and the OpenAI model. I will be using TypeScript to build the app, and by the end you’ll have a working translator built with the OpenAI GPT-4 model and LangChain’s messaging package. Set Up the Project To start with, createContinueContinue reading “How to Build Your First LLM Application Using LangChain and TypeScript”
Tag Archives: TypeScript
What is Type Assertion in TypeScript
In TypeScript, Type Assertions allow developers to explicitly specify the type of a variable to the TypeScript compiler. When the compiler cannot infer the type of a variable and the developer is more sure about the type, they can use a type assertion. Type assertions are a compile-time construct that does not result in runtimeContinueContinue reading “What is Type Assertion in TypeScript”
What are Discriminated Unions Patterns in TypeScript?
Recently, I came across a pattern named Discriminated Unions Types in TypeScript. In this blog post, let us learn about that. Discriminated Unions are a pattern where each type in the union has a common property. In TypeScript, a union type allows a variable to hold one of several specified types. A straightforward example of aContinueContinue reading “What are Discriminated Unions Patterns in TypeScript?”
What is Narrowing in TypeScript?
To understand narrowing, let’s begin with a problem scenario. Suppose you’re working with a custom type called myType, which is defined as a union of string and null. type mytype = string | null; let a: mytype = “FOO”; console.log(a!.toLowerCase()); // foo The code above should print “foo” in lowercase. Now, if you setContinueContinue reading “What is Narrowing in TypeScript?”
How to use TypeScript Custom Predicate for Narrowing
In TypeScript, narrowing refers to refining the type of a variable within a specific block of code. It allows TypeScript to infer a more particular type from a broader type based on runtime checks or control flow. Narrowing is used for better type safety, ensuring that only properties or methods on a type can be accessed. ItContinueContinue reading “How to use TypeScript Custom Predicate for Narrowing”
Key announcements from the Angular Team about Angular and its future at the ngPoland keynote
On November 6, 2024, I attended the Angular Team’s keynote at ng-Poland, Europe’s largest Angular conference. The keynote was presented by Mark Techson, Alex Rickabaugh, and Pawel Kozlowski from the Angular team. Here are some key features I gathered from the keynote announcement. These enhancements and additions are impressive and will significantly advance the AngularContinueContinue reading “Key announcements from the Angular Team about Angular and its future at the ngPoland keynote”
Do you know about TypeScript keyof operator?
In TypeScript, the keyof operator creates a union type of all the known public property names of the given type. To understand the actual use case of the keyof operator, let us consider the below example. There is a type created with an interface, interface IProduct { id: number; name: string; price: number; stock: number;ContinueContinue reading “Do you know about TypeScript keyof operator?”
Video – Partial Type in TypeScript
This video explains Partial Type in TypeScript. interface IProduct { name: string; price: number; } function SaveProduct(product: Partial<IProduct>) { console.log(product.name); console.log(product.price); } SaveProduct({ name: “Laptop”, price: 1000 }); SaveProduct({ name: “Mobile”, price: 500 }); SaveProduct({ name: “Tablet”}); https://www.youtube.com/watch?v=q5wE_QjBtVU
Interface Segregation Principle in TypeScript
The interface Segregation Principle is one of the fundamental principles of the SOLID principle. It says to keep the interface as small as possible. In the words of Uncle Bob, keep interfaces small so that classes don’t end up depending on things they don’t need. A client ( class) should not be forced to implementContinueContinue reading “Interface Segregation Principle in TypeScript”
Union and Intersection of types in TypeScript
Do you know, TypeScript allows union and Intersection of types? Why you need that? Let us assume you need to create a function that checks whether the passed value is boolean true and returns true, otherwise returns null. That function may look like below, function trueOrNull(foo: any): any { if (foo === true) { return true; } return undefined; } console.log(trueOrNull(88)); // null As you see, theContinueContinue reading “Union and Intersection of types in TypeScript”