Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some more to test
  • Loading branch information
Emyrk committed Oct 20, 2022
commit 1510183ebdd4bdf75f9350f0e20264c4e562c8ae
3 changes: 1 addition & 2 deletions coderd/util/slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func Overlap[T comparable](a []T, b []T) bool {
// Unique returns a new slice with all duplicate elements removed.
// This is a slow function on large lists.
// TODO: Sort elements and implement a faster search algorithm if we
//
// really start to use this.
// really start to use this.
func Unique[T comparable](a []T) []T {
cpy := make([]T, 0, len(a))
for _, v := range a {
Expand Down
15 changes: 8 additions & 7 deletions scripts/apitypings/testdata/generics/generics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ type Custom interface {

// StaticGeneric has all generic fields defined in the field
type StaticGeneric struct {
Static GenericFields[string, int, time.Duration] `json:"static"`
Static GenericFields[string, int, time.Duration, string] `json:"static"`
}

// DynamicGeneric can has some dynamic fields
type DynamicGeneric[C comparable, A any] struct {
Dynamic GenericFields[C, A, string] `json:"dynamic"`
Comparable C `json:"comparable"`
type DynamicGeneric[C comparable, A any, S Single] struct {
Dynamic GenericFields[C, A, string, S] `json:"dynamic"`
Comparable C `json:"comparable"`
}

type GenericFields[C comparable, A any, T Custom] struct {
type GenericFields[C comparable, A any, T Custom, S Single] struct {
Comparable C `json:"comparable"`
Any A `json:"any"`

Custom T `json:"custom"`
Again T `json:"again"`
Custom T `json:"custom"`
Again T `json:"again"`
SingleContraint S `json:"single_constraint"`
}
9 changes: 5 additions & 4 deletions scripts/apitypings/testdata/generics/generics.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// Code generated by 'make coder/scripts/apitypings/main.go'. DO NOT EDIT.

// From codersdk/generics.go
export interface DynamicGeneric<C extends comparable, A extends any> {
readonly dynamic: GenericFields<C, A, string>
export interface DynamicGeneric<C extends comparable, A extends any, S extends Single> {
readonly dynamic: GenericFields<C, A, string, S>
readonly comparable: C
}

// From codersdk/generics.go
export interface GenericFields<C extends comparable, A extends any, T extends Custom> {
export interface GenericFields<C extends comparable, A extends any, T extends Custom, S extends Single> {
readonly comparable: C
readonly any: A
readonly custom: T
readonly again: T
readonly single_constraint: S
}

// From codersdk/generics.go
export interface StaticGeneric {
readonly static: GenericFields<string, number, number>
readonly static: GenericFields<string, number, number, string>
}

// From codersdk/generics.go
Expand Down