This is (concept of)
Invisible static type checker for JavaScript
It is the child of TypeScript, but more simple and compatible with standards and Babel transpiler. Implementation mechanism is similar with asm.js.
It can be utilised if you just want try to use static types, if you have no intent to rewrite all your code on TypeScript (or FlowType) yet.
Type-checking without type declarations! (Type Inference).
As a bonus, your code will get many of type safety with your standard javascript transpiler or interpreter, even if you doesn't use Invisible TS checker.
No need for big documentation. Invisible TS is not a programming language, it designed just to bring type safety to javascript.
Even if developer doesn't know anything about type systems, hi can assume how client code will work, because Invisible TS using standard js:
Type declarations hidden in default values, described by javascript operators (void, ||, &&, undefined, null, Number, Boolean, String, Object).
(not implemented yet)
You can start using typescript functionality in babel-based project with low cost.
'use strict type'
// Variables //
let n = Number()
let i = 0 // the same as Number()
let s = "string"
let b = Boolean() // initial value - false, can't be undefined or null
let b3 = void Boolean // initial value - undefined
let any = undefined
let anyOf = Number || String || Boolean || Object || null || undefined
let uninitiated = void HTMLElement
let theSame = HTMLElement && undefined
let nullable = HTMLElement && null
// Functions //
// define function, that return boolean and require one argument:
void Boolean
function invert( value = Boolean() || TypeError() ){
return ! value
}
// Objects & Classes //
let o = Object()
let obj = {requiredProperty: HTMLCollection && null,
optionalProperty: undefined && "string"}
- If variable can change type, it should be declared before.
- [?] Default values should be declared for all variables and arguments.
How to cast types in javascript? There is one standard solution - you can call constructor as function, without operator new:
let b = Boolean("false")
console.log(b, typeof b) // true "boolean"
So, to describe how to convert one type to another, you can check ´this´ in constructor.
- Typescript has many parts - it is programming language, type-checker and transpiler all-in-one. Invisible TS is only type-checker (it doesn't extend the language, like typescript with interfaces and polymorphism).
- It introduce special syntax, and it doesn't look good with ES6 defaults and destructuring.
- Flowtype utilize special syntax to declare types (just like typescript), so typed code can't be simply copy-pasted into untyped javascript.
- It doesn't fully support Type Inference, mechanism used to hide type declarations.
- It hard to extend: It wasn't wrote on javascript.
This is just concept :)
Please star this repo and I will create type-checker with ESLint or/and Babel plugin.