or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

any.mdboolean.mdclass.mdcommunity.mdfunction.mdindex.mditeration.mdlist.mdmisc.mdnumber.mdobject.mdstring.mdtesting.mdunion.md

community.mddocs/

0

# Community Module

1

2

Community-contributed utilities providing specialized type checking and deep operations.

3

4

## Capabilities

5

6

### Deep Inclusion Checking

7

8

Check for deep inclusion within complex nested structures.

9

10

```typescript { .api }

11

/**

12

* Check if a type includes another type deeply within nested structures

13

* @param T - Type to search within

14

* @param U - Type to search for

15

* @returns 1 if U is found deeply within T, 0 otherwise

16

*/

17

type IncludesDeep<T, U> = IncludesDeepImpl<T, U>;

18

```

19

20

**Usage Examples:**

21

22

```typescript

23

import { Community } from "ts-toolbelt";

24

25

// Deep nested structure

26

type NestedObject = {

27

user: {

28

profile: {

29

settings: {

30

theme: "dark" | "light";

31

notifications: boolean;

32

};

33

};

34

};

35

};

36

37

// Check if "dark" is included deeply

38

type HasDarkTheme = Community.IncludesDeep<NestedObject, "dark">; // 1

39

40

// Check for non-existent type

41

type HasInvalidType = Community.IncludesDeep<NestedObject, "invalid">; // 0

42

43

// Array deep inclusion

44

type NestedArray = [1, [2, [3, ["hello", "world"]]]];

45

type HasString = Community.IncludesDeep<NestedArray, string>; // 1

46

type HasSymbol = Community.IncludesDeep<NestedArray, symbol>; // 0

47

```

48

49

### Literal Type Checking

50

51

Determine if a type is a literal type (specific value) rather than a general type.

52

53

```typescript { .api }

54

/**

55

* Check if a type is a literal type

56

* @param T - Type to check for literal status

57

* @returns 1 if T is a literal type, 0 otherwise

58

*/

59

type IsLiteral<T> = IsLiteralImpl<T>;

60

```

61

62

**Usage Examples:**

63

64

```typescript

65

import { Community } from "ts-toolbelt";

66

67

// Literal types

68

type IsStringLiteral = Community.IsLiteral<"hello">; // 1

69

type IsNumberLiteral = Community.IsLiteral<42>; // 1

70

type IsBooleanLiteral = Community.IsLiteral<true>; // 1

71

72

// General types

73

type IsStringGeneral = Community.IsLiteral<string>; // 0

74

type IsNumberGeneral = Community.IsLiteral<number>; // 0

75

type IsBooleanGeneral = Community.IsLiteral<boolean>; // 0

76

77

// Union literals vs general unions

78

type UnionLiteral = Community.IsLiteral<"red" | "green" | "blue">; // Implementation dependent

79

type UnionGeneral = Community.IsLiteral<string | number>; // 0

80

81

// Object and array literals

82

type ObjectLiteral = Community.IsLiteral<{ name: "John"; age: 30 }>; // 1

83

type TupleLiteral = Community.IsLiteral<[1, 2, 3]>; // 1

84

85

// Template literals

86

type TemplateLiteral = Community.IsLiteral<`Hello ${string}`>; // Implementation dependent

87

```

88

89

### Practical Applications

90

91

Real-world usage patterns for community utilities.

92

93

**Usage Examples:**

94

95

```typescript

96

import { Community, A } from "ts-toolbelt";

97

98

// Configuration validation

99

type Config = {

100

environment: "development" | "staging" | "production";

101

features: {

102

auth: {

103

provider: "oauth" | "saml";

104

settings: {

105

timeout: number;

106

retries: 3 | 5 | 10;

107

};

108

};

109

};

110

};

111

112

// Check if specific values are supported

113

type SupportsOAuth = Community.IncludesDeep<Config, "oauth">; // 1

114

type SupportsLDAP = Community.IncludesDeep<Config, "ldap">; // 0

115

type HasRetryLimit = Community.IncludesDeep<Config, 3>; // 1

116

117

// Type constraint validation

118

type ValidateConfigValue<T> = Community.IsLiteral<T> extends 1

119

? "literal_value"

120

: "general_type";

121

122

type EnvValidation = ValidateConfigValue<"production">; // "literal_value"

123

type TimeoutValidation = ValidateConfigValue<number>; // "general_type"

124

125

// API response validation

126

type ApiResponse = {

127

status: 200 | 404 | 500;

128

data: {

129

users: Array<{

130

id: string;

131

role: "admin" | "user" | "guest";

132

}>;

133

};

134

};

135

136

type HasAdminRole = Community.IncludesDeep<ApiResponse, "admin">; // 1

137

type HasModeratorRole = Community.IncludesDeep<ApiResponse, "moderator">; // 0

138

type HasSuccessStatus = Community.IncludesDeep<ApiResponse, 200>; // 1

139

140

// Form validation

141

type FormField<T> = {

142

value: T;

143

isLiteral: Community.IsLiteral<T>;

144

hasSpecificValue: <V>(value: V) => Community.IncludesDeep<T, V>;

145

};

146

147

type EmailField = FormField<string>; // isLiteral: 0

148

type StatusField = FormField<"pending" | "approved" | "rejected">; // isLiteral: implementation dependent

149

150

// Conditional type construction

151

type ConditionalType<T> = Community.IsLiteral<T> extends 1

152

? { literalValue: T; type: "specific" }

153

: { type: "general"; acceptedValues: T };

154

155

type StringType = ConditionalType<string>; // { type: "general"; acceptedValues: string }

156

type HelloType = ConditionalType<"hello">; // { literalValue: "hello"; type: "specific" }

157

```

158

159

## Types

160

161

```typescript { .api }

162

// Community module provides specialized utilities

163

// Implementation details are internal to the module

164

```