( env: TcbEnvironment, meta: TypeCtorMetadata, typeRef: string, typeRefWithGenerics: string, )
| 414 | } |
| 415 | |
| 416 | function constructTypeCtorParameter( |
| 417 | env: TcbEnvironment, |
| 418 | meta: TypeCtorMetadata, |
| 419 | typeRef: string, |
| 420 | typeRefWithGenerics: string, |
| 421 | ): string { |
| 422 | let initType: string | null = null; |
| 423 | |
| 424 | const plainKeys: string[] = []; |
| 425 | const coercedKeys: string[] = []; |
| 426 | const signalInputKeys: string[] = []; |
| 427 | |
| 428 | for (const {classPropertyName, transformType, isSignal} of meta.fields.inputs) { |
| 429 | if (isSignal) { |
| 430 | signalInputKeys.push(TcbExpr.quoteAndEscape(classPropertyName)); |
| 431 | } else if (!meta.coercedInputFields.has(classPropertyName)) { |
| 432 | plainKeys.push(TcbExpr.quoteAndEscape(classPropertyName)); |
| 433 | } else { |
| 434 | const propName = `ngAcceptInputType_${classPropertyName}`; |
| 435 | const isUnsafe = isUnsafeObjectKey(classPropertyName); |
| 436 | const access = isUnsafe ? `[${TcbExpr.quoteAndEscape(propName)}]` : `.${propName}`; |
| 437 | const coercionType = |
| 438 | transformType !== undefined ? transformType : `typeof ${typeRef}${access}`; |
| 439 | |
| 440 | coercedKeys.push( |
| 441 | `${isUnsafe ? TcbExpr.quoteAndEscape(classPropertyName) : classPropertyName}: ${coercionType}`, |
| 442 | ); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if (plainKeys.length > 0) { |
| 447 | initType = `Pick<${typeRefWithGenerics}, ${plainKeys.join(' | ')}>`; |
| 448 | } |
| 449 | if (coercedKeys.length > 0) { |
| 450 | let coercedLiteral = '{\n'; |
| 451 | for (const key of coercedKeys) { |
| 452 | coercedLiteral += `${key};\n`; |
| 453 | } |
| 454 | coercedLiteral += '}'; |
| 455 | initType = initType !== null ? `${initType} & ${coercedLiteral}` : coercedLiteral; |
| 456 | } |
| 457 | if (signalInputKeys.length > 0) { |
| 458 | const keyTypeUnion = signalInputKeys.join(' | '); |
| 459 | |
| 460 | const unwrapRef = env.referenceExternalSymbol( |
| 461 | R3Identifiers.UnwrapDirectiveSignalInputs.moduleName, |
| 462 | R3Identifiers.UnwrapDirectiveSignalInputs.name, |
| 463 | ); |
| 464 | const unwrapExpr = `${unwrapRef.print()}<${typeRefWithGenerics}, ${keyTypeUnion}>`; |
| 465 | initType = initType !== null ? `${initType} & ${unwrapExpr}` : unwrapExpr; |
| 466 | } |
| 467 | |
| 468 | if (initType === null) { |
| 469 | initType = '{}'; |
| 470 | } |
| 471 | |
| 472 | return `init: ${initType}`; |
| 473 | } |
no test coverage detected