charlesLoder / havarotjs

A Typescript package for getting syllabic data about Hebrew text with niqqud.
https://www.npmjs.com/package/havarotjs
MIT License
12 stars 6 forks source link

Classes that extend `Node` need greater type safety #98

Closed charlesLoder closed 1 year ago

charlesLoder commented 1 year ago

When calling next of prev on a class that extends Node, type safety is lost.

new Text("כִּסֵּ֣א").syllables.forEach(s => console.log(s.next.vowelName));
// Property 'vowelName' does not exist on type 'Node'.ts(2339)

You have to as cast as the type.

new Text("כִּסֵּ֣א").syllables.forEach(s => {
    const next = s.next as Syllable;
    console.log(next.vowelName); 
});

This is pretty ugly and annoying.