Generics, Type Parameter Constraints, Dictionaries in TS, etc.

Reusable components are incredibly important when programming. Creating a component that can work over a variety of types rather than a single one is key. Generics allows users to consume these components and use their own types.² Generics parameterize types the way that functions parameterize values. Types are constraints and the represent contracts between various entities.¹

With Generics, we get what is known as the type variable, a special kind of variable that works on types rather than values. We provide a type as a parameter to the dynamic function that we are building. For example:

Below, you’ll see…


Compile project in ‘loose mode’ and get tests to pass. [Rename all .js files to .ts ???] ← so scary! In the tsconfig.json file, add “noImplicitAny”: false, under “compilerOptions”.

In configuration , change— “noImplicitAny: true”. If this is set to true, it will provide errors on any arguments or variables where type has not been explicitly set, and you can work back from there to set types. Use type ‘any’ in the rare cases where you can not use basic types or union types.

DefinitelyTyped — open source project providing ambient type information, npm packages to bring in type information…


Following Along with Mike North’s Frontend Masters Tutorial

I recently wrote a post on my first steps of learning TypeScript; that blog is available here. This article will be another step in what I’m sure will be a long journey of learning TS. The tutorial that I’m following along with here was shared with me by one of my managers. I’m excited to be able to take my first course with Frontend Masters¹.

TypeScript is an open-source project?!?! Awesome! In my last post I talked about about aspects of the three parts of TS, but didn’t name them directly: Language…


A Strongly Typed, Object Oriented, Compiled Language

Learning TypeScript Along with an Academind Tutorial

TypeScript is a strict syntactical superset of JavaScript. It takes the JS language and adds new features and advantages to it. Browsers can’t execute TypeScript (neither can Node.js), so Typescript acts as a compiler that you run over your code to compile TypeScript code to JavaScript. It makes JS easier to use by adding ‘types’ to JavaScript while cutting down runtime errors by catching errors earlier during development.

TypeScript adds Types! …


Moving Away From REST API’s to Get Data From an API to Your Application

First thing to know: GraphQL is a specification (how it should work and look), not an implementation. There is no installing GraphQL, you implement it using a server library, a client framework like Apollo and playgrounds like GraphiQL or Graphcool to test out your queries.

GraphQL key points:

  • server-side runtime
  • fast, flexible, developer-friendly
  • gives clients exactly the data they want/have specified, not the entire payload of data
  • great relational queries — where all queries can be done in one query, no ‘over-fetching’²
  • gives backend developers a type system to develop a schema for data
  • strong data types reduce errors between…


Relationship Models

In our applications, we will develop multiple Models to represent our data. Our data, by default, can and will be connected in a multitude of ways, our objects will be related. To support the associations that our Models have with each-other, Mongoose has to be told in what ways our Models interact. In relational databases, like PostgreSQL, there is a concept of relationship (ex: foreign keys). This isn’t the case with NoSQL databases; don’t truly have a relationship.

***Relational and NoSQL database trade off: Query performance vs. consistency

Normalization: Using References

Line 6 does NOT establish a direct relationship…


Validating Data in MongoDB

Great Article on Data Validation & Image credit: Sharjeel Ashraf

“In computer science, data validation is the process of ensuring data has undergone data cleansing to ensure they have, that is, that they are both correct and useful. It uses routines, often called “validation rules”, “validation constraints”, or “check routines”, that check for correctness, meaningfulness, and security of data that are input to the system. The rules may be implemented through the automated facilities of a data dictionary, or by the inclusion of explicit application program validation logic of the computer and its application.”²

On line 8, we are requiring the presence of a value for the attribute “name”…


Building our Backend Database w/ MongoDB

MongoDb is a document database², aka a NoSQL database. It’s not a relational database. There are no tables, schemas, views, records or columns¹ in a NoSQL db, instead the data is split up into collections, which are a lot like tables. These collections store documents, which resemble records (row in a table) in a SQL db. Documents, just like records, auto-generate a unique id (“_id”:). You store json objects in MongoDB and MongoDB gives us back json objects when we query our data.

Similar to npm, Homebrew is a package manager for MacOS. If you haven’t installed Homebrew previously, visit…


JavaScript Asynchronous Programming / Callback Functions / Promises / Async and Await

Synchronous Programming → Blocking . Each statement in your code will executed one after the other. Each statement must wait until the previous statement has completed executing.

Asynchronous Programming → Non-Blocking (does not mean concurrent or multi-threaded). The programs we are building are single-threaded. Any program that is working with network access is dealing with async code.

Starting a new application, cd into your desired path location and make a new folder: mkdir <app_name> . Change directory into this app type in terminal command: npm init — — yes to set up your package.json file. Next, make a new file…


Deeper Dive into Express — Middleware, Environments, Configuration, Environment Variables, Debugging, Templating Engines, Database Integration, Properly Restructuring Our Express Routes/Files

These Blog Posts are a Series of My Notes While Following Along: ‘Programming With Mosh’

Express is a bunch of middleware functions. Middleware functions are called sequentially. Every route handler function ( (req, res) => {res.send(‘Hello World’)} ) is technically a middleware function.

Built-In Middleware²

express.json() — middleware: parses body of the request, if there’s a json object it populates req.body property

express.urlencoded() — middleware: parses incoming requests with url encoded payloads parses req.body like a json object

express.static(‘public’) — all of the static assests of the app will live in a ‘public folder’ (((create that folder in the main folder)))

Code Snippet of Built In Middleware

Custom Middleware

Custom middleware functions should be built…

Osha Groetz

Software Engineer. A new addict of ReactJS & Javascript, CSS & APIs, with a little dabbling in Ruby, Ruby On Rails…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store