How to use the tsTypeLiteral function from @babel/types

Find comprehensive JavaScript @babel/types.tsTypeLiteral code examples handpicked from public code repositorys.

31
32
33
34
35
36
37
38
39
40
    properties.push(
      t.tsIndexSignature([stringKey], t.tsTypeAnnotation(index)),
    );
  }

  return t.tsTypeLiteral(properties);
},
string(schema) {
  if (schema.enum) {
    return t.tsUnionType(
fork icon2
star icon14
watch icon2

+ 23 other calls in file

33
34
35
36
37
38
39
40
41
42
function createTypeDoneVariant({ status, contractName }) {
  /**
   * status: 'ok';
   * answer: typed.Get<typeof registerRequestOk>;
   */
  return t.tsTypeLiteral([
    t.tsPropertySignature(
      t.identifier('status'),
      t.tsTypeAnnotation(t.tsLiteralType(t.stringLiteral(status))),
    ),
fork icon2
star icon14
watch icon2

+ 23 other calls in file

7
8
9
10
11
12
13
14
15
16
  [t.arrayExpression()]
),
{
  typeParameters: t.tsTypeParameterInstantiation([
    t.tsArrayType(
      t.tsTypeLiteral([
        t.tsPropertySignature(
          t.identifier('id'),
          t.tsTypeAnnotation(t.tsStringKeyword())
        )
fork icon0
star icon31
watch icon2

+ 5 other calls in file

16
17
18
19
20
21
22
23
24
25
  return t.objectProperty(t.stringLiteral(key), t.identifier(key === name ? key : name))
}))  

if (hasTsType) {
  objectPattern.typeAnnotation = t.tsTypeAnnotation(
    t.tsTypeLiteral(
      params.map((param, index) => {
        const key = index ? (index === 1 ? 'record' : 'index') : 'text'
        return t.tsPropertySignature(
          t.identifier(key),
fork icon0
star icon5
watch icon2

+ 7 other calls in file

65
66
67
68
69
70
71
72
73
74
  }
}

function typeFor(path, value) {
  if (typeof value === 'object' && !!value) {
    return t.tsTypeLiteral(
      Object.keys(value).map(key => {
        let propertyValue = value[key];
        let propertyValueType =
          path.length === 0 && key === 'environment'
fork icon0
star icon1
watch icon0

+ 11 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)