[Top] [All Lists]

Re: typescript [was: Re: [xsl] How to write (existential) predicates with maps/Why is there no effective boolean value for a map?]

2019-02-14 06:08:20
On Wed, Feb 13, 2019 at 4:38 PM Liam R. E. Quin 
liam(_at_)fromoldbooks(_dot_)org <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

[garbled gibberish here]

Sorry, that was I think the problem of mailer.

Ungarbling, i get,
class Student {
    fullName: string;
    constructor(public firstName: string, public middleInitial: string,
public lastName: string) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;

interface Person {
    firstName: string;
    lastName: string;

function greeter(person : Person) {
    return "Hello, " + person.firstName + " " + person.lastName;

let user = new Student("Jane", "M.", "User");

document.body.innerHTML = greeter(user);

So you are asking, does a Student object confom to the Person
interface?  That is, does the object have the required public fields.
We can see by inspection that it does.

From the syntax of above code (written above your comment), I can find only
following relationship between class Student and interface Person,
The constructor of Student mentions two of the fields of interface Person.
Is this sufficient to say that, class Student conforms to interface Person?
That could be debatable. On one side, Student's constructor is like any
*function*. Can function's parameters establish that, a class is
implementing an interface? (I'm tending to disagree). While on the other
hand, constructor is a special function for a class implying creation of
its objects, and from this point of view I find your points correct.

I'm not an expert with TypeScript yet (but its now on my list of
learnings!). Therefore, my above comments may not carry much weight. I
would assume generally, that TypeScript is / could be a nice language.

Correct. However, the Student object has the same structure as a Person
object. Typescript uses structural typing, not named typing.

Ok. Looking forward to learn such concepts about TypeScript.

Thanks to Dimitre, for mentioning TypeScript's name in the related thread,
and also for his comments.

Mukul Gandhi
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
<Prev in Thread] Current Thread [Next in Thread>