You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ditto, was confused in the lesson how simply kind: 'song' on the class definition could later be used to test in the if condition. Alas, it can't be used, as seen in the compiled JS code:
varSong=/** @class */(function(){functionSong(title,duration){this.title=title;this.duration=duration;}returnSong;}());varPlaylist=/** @class */(function(){functionPlaylist(name,songs){this.name=name;this.songs=songs;}returnPlaylist;}());functionisSong(item){return'title'initem;}functiongetItemName(item){// if (isSong(item)) {if(item.kind==='song'){returnitem.title;}returnitem.name;}varsongName=getItemName(newSong('Wonderful Wonderful',300000));console.log('Song name:',songName);varplaylistName=getItemName(newPlaylist('The Best Songs',[newSong('The Man',300000)]));console.log('Playlist name:',playlistName);
Tried TypeScript 4.2.4 and 2.7.2 (lesson version).
kind is forced to have a type of 'song' but it has to be assigned somewhere in the TypeScript which the example missing. Since const isn't allowed in class definitions the next best thing is readonly:
Hello,
In "16-in-operator-literal-type-guard" folder I run
tsc
and thennode app/dist.js
and the output is:However, if I switch the commenting out between lines 16 and 17 from:
to
then the output is properly:
It seems like something with the
kind
approach is not working properly.The text was updated successfully, but these errors were encountered: