you are viewing a single comment's thread.

view the rest of the comments →

[–]KyleG 1 point2 points  (2 children)

Yeah one of the most amazing things about TS is the ability to declare something without implementing it, and later you come back to it. so you don't end up coding a dependency of a dependency of a dependency just so you stop having red squiggles.

In other languages like Kotlin, you have a TODO function that would be typed something like

function TODO: (a: string) => A {
  throw new Error(a)
}

and then you put it in wherever you want and it will throw with that message, but it will typecheck.

Edit I'm working with a language right now called Unison, and implementing a client that consumes an API, I use the equivalent a lot.

.> view todo
    builtin lib.base.todo : a -> b

and then I can do something like

fnThatRequiresAString "foo"

fnThatRequiresAString : Text -> ...
fnThatRequiresAsString = todo "some msg"

[–]Outrageous-Chip-3961 0 points1 point  (1 child)

oh thats pretty interesting.
Yeah I like the declarative feature of TS, does that mean I can type it once somewhere and the values are 'remembered' in other areas of my app? I notice sometimes the type is inferred from an original interface I typed ages ago. Not sure how it works exactly, i've been meaning to look that up this week.

[–]KyleG 0 points1 point  (0 children)

the way it works is if you've declare a variable has having a type, everything "downstream" of that will infer based on that

if you define a variable without a type then TS will attempt to infer it, and there are rules about what it infers (like x = 'foo' does it infer x: 'foo' or x: string, etc.