Apostrophe CMS Main Site Forum Home

Typescriptification of Apostrophe


#1

Just curious if there has been any discussion about migrating Apostrophe to Typescript. It’s a bit of a process, but in my (brief) experience with Typescript, it hasn’t been as much of a bear as it seems, and the built in documentation is a huge productivity boost.


#2

Open to discussing it! Not sure how much of an issue it creates for those not fans of typescript, if any? Also not sure how easy it would be to make Apostrophe’s functional object-oriented system play nicely with it (which doesn’t mean it can’t be done, just that it hasn’t been researched).

My gut says “probably not for 3.0” because our to-do list for 3.0 is pretty long already, but I have an open mind…


#3

Regarding non-fans: I’ve not encountered any anti-fans, just the uninitiated. It is an absolutely corrupting idea: once you get it you simply cannot go back.

Understood on 3.0, but a comment when it does hit the radar: the best approach I’ve seen is to convert exactly 1 file. Convert the simplest easiest file you can, and have the compiler running (the compiler works in every text editor) while you work. Save, autocompile. Once you do 1 file, you want to do 10, and so forth.

Several incredibly strong arguments for Typescript:

Absolutely corrupting.


#4

Apostrophe has a lot of methods that accept more than one calling syntax, i.e. name, value or passing an object, for instance. Not sure how that plays with Typescript?


#5

Well I’ll state for the record that I’m not a Typescript expert, just picking it up in the last month, but here’s what I grok as it relates to the question:

A bit of background: Typescript requires having a definition file for your modules to get full functionality, though you can get pretty far in a .ts file with:

const makeSandwich = (bread: string, cheese: any, meat?: string) => {
  ...
}

bread would be a string,
cheese could be anything
meat is optional string

? denoting optional. optional values go last.

A step further is to provide definition files, which are a bit more of an undertaking, but they end up giving you cool stuff like*:

  • this is where the 80% reduction in Google comes from: most of what you need is right in your editor right as you type it.

And it looks like Microsoft has a package to autogenerate a baseline of def files (Medium post on this)

So, essentially, it should play fine.


#6

@apropostrophe I’ve kicked off an effort to provide typings for Apostrophe here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/apostrophe/index.d.ts

Please contribute if you can!