Why is JavaScript not sufficient itself?

Basic Types

  • Boolean
  • Number
  • String
  • Array
  • Object
  • Undefined
  • Enum
  • Tuple
  • Any
  • Void
  • Never

Interfaces - Optional Properties


interface SquareConfig {
    color?: string;
    width?: number;
}

function createSquare(config: SquareConfig) {
    // ...
}

let mySquare = createSquare({color: "black", widht: 50});
                
Compile time error:

test.ts(17,47): error TS2345: Argument of type
'{ color: string; widht: number; }'
is not assignable to parameter of type 'SquareConfig'.
Object literal may only specify known properties,
and 'widht' does not exist in type 'SquareConfig'.
                

Thanks

www.typescriptlang.org