our-own-type-system icon indicating copy to clipboard operation
our-own-type-system copied to clipboard

Basic JavaScript type checker, in 100 lines.

Our own type system

A compiler which checks types for 3 scenarios:

  1. Issue with un-compatible types on declaration and expression
fn("craig-string"); // throw with string vs number
function fn(a: number) {}
  1. Issue with unknown type on declaration and expression
fn("craig-string"); // throw with string vs ?
function fn(a: made_up_type) {} // throw with bad type
  1. Issue with property name
interface Person {
  name: string;
}
fn({ nam: "craig" }); // throw with "nam" vs "name"
function fn(a: Person) {}