DEV Community

Discussion on: TypeScript vs JavaScript🤔

Collapse
 
bwca profile image
Volodymyr Yepishev

Aww... no generics or mapped types? :>

Thread Thread
 
peerreynders profile image
peerreynders • Edited
/**
 * Factory for the core structure of a suite
 * @template {object} [U = Record<string,never>]
 * @param {import('./internal').State<U>} state
 * @returns {import('./internal').Context<U>}
 */
function context(state) {
  return {
    tests: [],
    before: [],
    after: [],
    bEach: [],
    aEach: [],
    only: [],
    skipped: 0,
    state,
  };
}
Enter fullscreen mode Exit fullscreen mode

Preact compat

Thread Thread
 
bwca profile image
Volodymyr Yepishev

Interesting, but can it do the heavy lifting ts does? I.e. generating a type containing all possible property paths for a nested object, i.e. like this?

Thread Thread
 
peerreynders profile image
peerreynders

Basically the types live in a TypeScript declaration file so it's just TypeScript.

Clean separation between type space (TypeScript) and value space (JavaScript).

With that setup it is now possible to only perform static type analysis on demand. In this case it's used to arrive at "well formed JavaScript" while keeping the source under developer control.

That said you can arrive at a similar TS workflow with vite. esbuild transforms TS "blazingly fast" without doing any type checking. So you can worry about tests first, types second.