How to use the @jsii/spec.isNamedTypeReference function in @jsii/spec

To help you get started, we’ve selected a few @jsii/spec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii / lib / assembler.ts View on Github external
async: _isPromise(returnType) || undefined,
      static: _isStatic(symbol) || undefined,
      locationInModule: this.declarationLocation(declaration),
    };
    method.variadic = method.parameters?.some(p => !!p.variadic) || undefined;

    this._verifyConsecutiveOptionals(declaration, method.parameters);

    method.docs = this._visitDocumentation(symbol, ctx);

    // If the last parameter is a datatype, verify that it does not share any field names with
    // other function arguments, so that it can be turned into keyword arguments by jsii frontends
    // that support such.
    const lastParamTypeRef = apply(last(parameters), x => x.type);
    const lastParamSymbol = last(signature.getParameters());
    if (lastParamTypeRef && spec.isNamedTypeReference(lastParamTypeRef)) {
      this._deferUntilTypesAvailable(symbol.name, [lastParamTypeRef], lastParamSymbol!.declarations[0], (lastParamType) => {
        if (!spec.isInterfaceType(lastParamType) || !lastParamType.datatype) { return; }

        // Liftable datatype, make sure no parameter names match any of the properties in the datatype
        const propNames = this.allProperties(lastParamType);
        const paramNames = new Set(parameters.slice(0, parameters.length - 1).map(x => x.name));
        const sharedNames = intersection(propNames, paramNames);

        if (sharedNames.size > 0) {
          this._diagnostic(
            declaration,
            ts.DiagnosticCategory.Error,
            `Name occurs in both function arguments and in datatype properties, rename one: ${Array.from(sharedNames).join(', ')}`);
        }
      });
    }
github aws / jsii / packages / jsii / lib / assembler.ts View on Github external
// Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
      // erased, and identify the closest exported base class, should there be one.
      while (base && this._isPrivateOrInternal(base.symbol)) {
        LOG.debug(`Base class of ${colors.green(jsiiType.fqn)} named ${colors.green(base.symbol.name)} is not exported, erasing it...`);
        erasedBases.push(base);
        base = (base.getBaseTypes() ?? [])[0];
      }
      if (!base) {
        // There is no exported base class to be found, pretend this class has no base class.
        continue;
      }

      // eslint-disable-next-line no-await-in-loop
      const ref = await this._typeReference(base, type.symbol.valueDeclaration);

      if (!spec.isNamedTypeReference(ref)) {
        this._diagnostic(base.symbol.valueDeclaration,
          ts.DiagnosticCategory.Error,
          `Base type of ${jsiiType.fqn} is not a named type (${spec.describeTypeReference(ref)})`);
        continue;
      }
      this._deferUntilTypesAvailable(fqn, [ref], base.symbol.valueDeclaration, (deref) => {
        if (!spec.isClassType(deref)) {
          this._diagnostic(base.symbol.valueDeclaration,
            ts.DiagnosticCategory.Error,
            `Base type of ${jsiiType.fqn} is not a class (${spec.describeTypeReference(ref)})`);
        }
      });
      jsiiType.base = ref.fqn;
    }

    //
github aws / jsii / packages / jsii-reflect / lib / type-ref.ts View on Github external
public get fqn(): string | undefined {
    return jsii.isNamedTypeReference(this.spec) ? this.spec.fqn : undefined;
  }
github aws / jsii / packages / jsii-pacmak / lib / targets / dotnet / dotnettyperesolver.ts View on Github external
public toDotNetType(typeref: spec.TypeReference): string {
    if (spec.isPrimitiveTypeReference(typeref)) {
      return this.toDotNetPrimitive(typeref.primitive);
    } else if (spec.isCollectionTypeReference(typeref)) {
      return this.toDotNetCollection(typeref);
    } else if (spec.isNamedTypeReference(typeref)) {
      return this.toNativeFqn(typeref.fqn);
    } else if (typeref.union) {
      return 'object';
    }
    throw new Error(`Invalid type reference: ${JSON.stringify(typeref)}`);

  }
github aws / jsii / packages / jsii-reflect / lib / type-ref.ts View on Github external
public get type(): Type | undefined {
    if (!jsii.isNamedTypeReference(this.spec)) {
      return undefined;
    }

    return this.system.findFqn(this.spec.fqn);
  }
github aws / jsii / packages / jsii / lib / assembler.ts View on Github external
continue;
        }

        baseInterfaces.add(iface);
      }
    };

    processBaseTypes(baseTypes);

    const typeRefs = Array.from(baseInterfaces).map(async iface => {
      const decl = iface.symbol.valueDeclaration;
      const typeRef = await this._typeReference(iface, decl);
      return { decl, typeRef };
    });
    for (const { decl, typeRef } of await Promise.all(typeRefs)) {
      if (!spec.isNamedTypeReference(typeRef)) {
        this._diagnostic(decl,
          ts.DiagnosticCategory.Error,
          `Interface of ${fqn} is not a named type (${spec.describeTypeReference(typeRef)})`);
        continue;
      }

      this._deferUntilTypesAvailable(fqn, [typeRef], decl, (deref) => {
        if (!spec.isInterfaceType(deref)) {
          this._diagnostic(decl,
            ts.DiagnosticCategory.Error,
            `Inheritance clause of ${fqn} uses ${spec.describeTypeReference(typeRef)} as an interface`);
        }
      });

      result.push(typeRef);
    }