How to use the objectTypeSpreadProperty function from @babel/types

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

@babel/types.objectTypeSpreadProperty represents an object type property spread, which can be used to merge multiple object type properties into a single property.

576
577
578
579
580
581
582
583
584
585
  }: Selection,
  state: State,
  concreteType: ?string,
) {
  if (kind === 'ModuleImport') {
    return t.objectTypeSpreadProperty(
      t.genericTypeAnnotation(t.identifier(key)),
    );
  }
  if (schemaName === '__typename' && concreteType) {
fork icon0
star icon0
watch icon1

How does @babel/types.objectTypeSpreadProperty work?

@babel/types.objectTypeSpreadProperty is used to represent a property spread in an object type. This spread property allows multiple object type properties to be merged into a single object property. For example, consider the following TypeScript code: typescript Copy code {{{{{{{ class="!whitespace-pre hljs language-typescript">type Point2D = { x: number, y: number }; type Point3D = { z: number } & Point2D; The Point3D type is a combination of Point2D and an additional z property. We could represent the Point3D type using @babel/types.objectTypeAnnotation as follows: less Copy code {{{{{{{ class="!whitespace-pre hljs language-less">t.objectTypeAnnotation([ t.objectTypeSpreadProperty( t.identifier('Point2D') ), t.objectTypeProperty( t.identifier('z'), t.numberTypeAnnotation() ) ]) Here, the objectTypeSpreadProperty represents the Point2D type, which is merged with the z property using objectTypeProperty to create the final Point3D type. In summary, @babel/types.objectTypeSpreadProperty is used to represent the spreading of object type properties. It is used in conjunction with other @babel/types nodes to build up complex object types.

Ai Example

1
2
3
4
5
6
const t = require("@babel/types");

const spreadProp = t.objectTypeSpreadProperty(t.identifier("foo"));

console.log(spreadProp);
// Output: { type: 'ObjectTypeSpreadProperty', argument: { type: 'Identifier', name: 'foo' } }

In this example, @babel/types.objectTypeSpreadProperty is used to create an object type spread property node with an identifier foo. The resulting AST node can then be used in other Babel transformations.

Other functions in @babel/types

Sorted by popularity

function icon

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