-
Notifications
You must be signed in to change notification settings - Fork 69
Typescript backend spec #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Typescript backend spec #1247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -59,32 +59,33 @@ import Baz from "foo/bar/baz" | |||||
| Baz.fooBar | ||||||
| ``` | ||||||
|
|
||||||
| ## Types | ||||||
| ## Type Definitions | ||||||
|
|
||||||
| ### Records | ||||||
| ### TypeAliasDefinition | ||||||
|
|
||||||
| Generates an interface with a function matching the name of the interface | ||||||
| TypeAliasDefinitions have a direct one-to-one mapping to typescripts type aliases | ||||||
|
|
||||||
| For example: | ||||||
| #### Special Record TypeAliasDefinition Constructors | ||||||
|
|
||||||
| Elm records come with a constructor that allows for a value of that record to be created with positional arguments. | ||||||
| To match this behaviour, every record definition generates, additionally, a function matching the name of the record type. | ||||||
|
|
||||||
| Example: | ||||||
|
|
||||||
| ```elm | ||||||
| type alias Foo = { name: String, age: Int } | ||||||
| type alias Foo = {a: String, b: Int} | ||||||
| ``` | ||||||
|
|
||||||
| should produce | ||||||
| creates the following in typescript | ||||||
|
|
||||||
| ```typescript | ||||||
| interface Foo { | ||||||
| name: string | ||||||
| age: number | ||||||
| } | ||||||
| type Foo = { a: string, b: number } | ||||||
|
|
||||||
| function Foo(name: string, age: number): Foo { | ||||||
| return { name, age } | ||||||
| } | ||||||
| // an additional function matching the name of the type | ||||||
| function Foo(a: string, b: number): Foo = {a, b} | ||||||
| ``` | ||||||
|
|
||||||
| ### Custom types | ||||||
| ### CustomTypeDefinition | ||||||
|
|
||||||
| Custom types should generate an object having a `kind` field that equals the constructor name | ||||||
|
|
||||||
|
|
@@ -101,9 +102,160 @@ type FooBar = | |||||
| | { kind: "Baz", arg1: number } | ||||||
| ``` | ||||||
|
|
||||||
| ### Basic types | ||||||
| ## Type Expressions | ||||||
|
|
||||||
| ### Variable | ||||||
|
|
||||||
| A type variable maps directly to a type argument in Typescript | ||||||
|
|
||||||
| ```elm | ||||||
| type alias Foo a = ... | ||||||
| ``` | ||||||
|
|
||||||
| can be conveniently translated to | ||||||
|
|
||||||
| ```typescript | ||||||
| type alias Foo<A> = ... | ||||||
|
||||||
| type alias Foo<A> = ... | |
| type Foo<A> = ... |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: 'appropraite' should be 'appropriate'.
| The most appropraite translation of an extensible record is an intersection of record types, and this is how we map them. | |
| The most appropriate translation of an extensible record is an intersection of record types, and this is how we map them. |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: 'Instrinsic' should be 'Intrinsic'.
| ### Instrinsic Types | |
| ### Intrinsic Types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TypeScript function syntax is incorrect. It should use arrow function syntax
=> {a, b}or traditional function syntax withreturn {a, b}.