!xfqwqigUlAuUTEIPwA:matrix.org

TypeScript

728 Members
A superset of JavaScript that compiles to clean JavaScript output. https://www.typescriptlang.org/16 Servers

Load older messages


Timestamp Message
21 Jan 2020
01:47:50@gitter_keithlayne:matrix.orgKeith Layne (Gitter)Then it becomes nominal
01:49:00@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) what's the intuition around having only structural typing for classes
01:49:33@gitter_keithlayne:matrix.orgKeith Layne (Gitter)Are you asking why? Or how to develop intuition about structural types?
01:49:44@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) "why"
01:50:22@gitter_keithlayne:matrix.orgKeith Layne (Gitter) Cause Anders says so? I don't know. It was a design decision.
01:50:31@gitter_tusharmath:matrix.orgTushar Mathur (Gitter):D
01:50:39@gitter_tusharmath:matrix.orgTushar Mathur (Gitter)even for classes?
01:50:57@gitter_tusharmath:matrix.orgTushar Mathur (Gitter)that can cause bugs in the program.
01:51:54@gitter_keithlayne:matrix.orgKeith Layne (Gitter) The class is a function. The value A is the constuctor. The type A is the interface that the constructor returns. So the interfaces A and B in your example are indistinguishable.
01:53:19@gitter_keithlayne:matrix.orgKeith Layne (Gitter) So I'd say "it can cause bugs" is a result of not understanding or misusing the language. Which is not a criticism of you or anybody. It's just that TS is different than other languages, and blindly following the same patters absolutely can cause bugs.
01:53:40@gitter_keithlayne:matrix.orgKeith Layne (Gitter) (edited) ... same patters absolutely ... => ... same patterns absolutely ...
01:54:06@gitter_tusharmath:matrix.orgTushar Mathur (Gitter)Adding a private property is a hack.
01:54:51@gitter_keithlayne:matrix.orgKeith Layne (Gitter) If you say so. But you want nominal types in a language that's structurally typed, so it's not that surprising that it requires a hack.
01:55:15@gitter_tusharmath:matrix.orgTushar Mathur (Gitter)hmm .... that makes sense.
01:57:31@gitter_keithlayne:matrix.orgKeith Layne (Gitter) There are maybe a couple other ways to get effectively nominal types, but I don't remember offhand. You can probably search "nominal" and find lots of results in the TS repo.
01:58:26@gitter_tusharmath:matrix.orgTushar Mathur (Gitter)
class A {     
    constructor(readonly name: string) {}
}

class B { 
    constructor(readonly name: string) {}
}


 function foo(a: A): void {
     if (a instanceof A) {
         // I feel silly, putting this check here

     } 
}


foo(new B(''))
02:01:30@gitter_keithlayne:matrix.orgKeith Layne (Gitter) yeah the key there is that A has different meanings in those two positions. But I get what you mean.
02:05:38@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) Also for me the problem is that I don't control over the code of A so I can not go and add the private property as you suggested.
02:05:52@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) (edited) ... property asyou ... => ... property you ...
02:07:42@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) apparently flow as a solution : https://flow.org/en/docs/lang/nominal-structural/#toc-nominal-typing
02:50:59@gitter_natrina:matrix.orgNathima (Gitter) joined the room.
02:51:00@gitter_natrina:matrix.orgNathima (Gitter) Hey team, I am trying to do some cleanup of my typescript implementation, so I'm hoping for some clarify points. In the tsconfig.json are typeRoots and types mutually exclusive? Documentation has some weird stess points. It mentions states that using typeRoots disables @types, while using types also disables @types, but they do not mention disabling each other. I am trying to use types to include certain packages, and then use a typesRoots within my own package so that I don't need to do things like /// <reference types="../types" /> in all of my files. Is it possible to have TS globally import my reference?
02:53:50@gitter_natrina:matrix.orgNathima (Gitter) My next question, is that even if I include my /// <refrence />, my JSDoc is not appearing in my IDE (intelliJ). It just shows as No documentation found., despite having clear /** .. */ documentation defined. Is there a flag that I am missing that will enable this?
04:48:22@gitter_anyhowstep:matrix.orgAnyhowStep (Gitter) @tusharmath you're not the first to bring it up. The TS issues page has a bunch of issues opened with people asking the behavior be changed. However, it's probably too late to do so.
04:48:25@gitter_anyhowstep:matrix.orgAnyhowStep (Gitter)Also, a lot of JS is structurally typed.
04:48:41@gitter_tusharmath:matrix.orgTushar Mathur (Gitter) @AnyhowStep Yes.
04:49:02@gitter_anyhowstep:matrix.orgAnyhowStep (Gitter) Like promises. Returning { then : "hi" } inside a promise causes errors, IIRC
05:39:18@gitter_simoami:matrix.orgSimo Moujami (Gitter)

Hello, anyone familiar with ts-node-dev? I added a script command to package.json to transpile typescript and watch for file changes:

    "dev": "ts-node-dev --respawn --transpileOnly --project tsconfig.server.json ./server/index.ts",

The server starts fine but file changes are not detected. If on the other hand I change a file in the output folder build/, then tsnd detects the change there, but not in the source directory

05:39:31@gitter_simoami:matrix.orgSimo Moujami (Gitter) (edited) ... ``` "dev": "ts-node-dev ... => ... ``` "dev": "ts-node-dev ...
05:39:54@gitter_simoami:matrix.orgSimo Moujami (Gitter) (edited) ... If on the other handI ... => ... If I ...

There are no newer messages yet.


Back to Room List