invalid-alternate-type
@azure-tools/typespec-client-generator-core/invalid-alternate-typeSeverity: error
This diagnostic is issued when @alternateType is applied to a scalar source type with a non-scalar alternate type.
Impact
Section titled “Impact”- Area: SDK type substitution. Blocks an invalid
@alternateTypereplacement that would change a scalar into a non-scalar SDK type. - Not affected: The source scalar and its wire encoding remain unchanged.
❌ Incorrect Usage
Section titled “❌ Incorrect Usage”scalar storageDateTime extends utcDateTime;model DateWrapper { value: string;}@@alternateType(storageDateTime, DateWrapper); // scalar source cannot use a model alternate typeDiagnostic Message
Section titled “Diagnostic Message”TCGC reports:
Invalid alternate type. If the source type is Scalar, the alternate type must also be Scalar. Found alternate type kind: 'Model'✅ How to Fix
Section titled “✅ How to Fix”Use a scalar alternate type when the source is a scalar, or apply @alternateType to a non-scalar source when replacing it with a non-scalar shape:
scalar clientDateTime extends string;@@alternateType(storageDateTime, clientDateTime);