-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltins.go
35 lines (31 loc) · 1.14 KB
/
builtins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package guts
import "github.com/coder/guts/bindings"
// Some references are built into either Golang or Typescript.
var (
// builtInComparable is a reference to the 'comparable' type in Golang.
builtInComparable = bindings.Identifier{Name: "Comparable"}
// builtInRecord is a reference to the 'Record' type in Typescript.
builtInRecord = bindings.Identifier{Name: "Record"}
)
// RecordReference creates a reference to the 'Record' type in Typescript.
// The Record type takes in 2 type parameters, key and value.
func RecordReference(key, value bindings.ExpressionType) *bindings.ReferenceType {
return bindings.Reference(builtInRecord, key, value)
}
func (ts *Typescript) includeComparable() {
// The zzz just pushes it to the end of the sorting.
// Kinda strange, but it works.
_ = ts.setNode(builtInComparable.Ref(), typescriptNode{
Node: &bindings.Alias{
Name: builtInComparable,
Modifiers: []bindings.Modifier{},
Type: bindings.Union(
ptr(bindings.KeywordString),
ptr(bindings.KeywordNumber),
ptr(bindings.KeywordBoolean),
),
Parameters: []*bindings.TypeParameter{},
Source: bindings.Source{},
},
})
}