···
···
// Apply @default decorator if present
const rawDefault = getDefault(this.program, scalar);
const defaultValue = this.processDefaultValue(rawDefault);
418
-
let defWithDefault: any = { ...scalarDef };
421
+
let defWithDefault: LexObjectProperty = { ...scalarDef };
if (defaultValue !== undefined) {
// Check if it's a Type (model reference for tokens)
···
// Validate that the default value matches the type
this.assertValidValueForType(scalarDef.type, defaultValue, scalar);
434
-
defWithDefault = { ...defWithDefault, default: defaultValue };
437
+
// Type-safe narrowing based on both the type discriminator and value type
438
+
if (scalarDef.type === "boolean" && typeof defaultValue === "boolean") {
439
+
(defWithDefault as LexBoolean).default = defaultValue;
440
+
} else if (scalarDef.type === "integer" && typeof defaultValue === "number") {
441
+
(defWithDefault as LexInteger).default = defaultValue;
442
+
} else if (scalarDef.type === "string" && typeof defaultValue === "string") {
443
+
(defWithDefault as LexString).default = defaultValue;
···
if (scalarDef.type === "integer") {
const minValue = getMinValue(this.program, scalar);
if (minValue !== undefined) {
442
-
(defWithDefault as any).minimum = minValue;
452
+
(defWithDefault as LexInteger).minimum = minValue;
const maxValue = getMaxValue(this.program, scalar);
if (maxValue !== undefined) {
446
-
(defWithDefault as any).maximum = maxValue;
456
+
(defWithDefault as LexInteger).maximum = maxValue;
···
// Apply @default decorator if present
const rawDefault = getDefault(this.program, union);
const defaultValue = this.processDefaultValue(rawDefault);
477
-
let defWithDefault: any = { ...unionDef };
487
+
let defWithDefault: LexString = { ...unionDef as LexString };
if (defaultValue !== undefined) {
// Check if it's a Type (model reference for tokens)
···
`Use @inline to inline them at usage sites, use @token models for known values, or use string literals.`,
520
-
} else if (unionDef.type === "integer" && (unionDef as any).enum) {
530
+
} else if (unionDef.type === "integer" && (unionDef as LexInteger).enum) {
// Integer enums can also be defs
const defName = name.charAt(0).toLowerCase() + name.slice(1);
const description = getDoc(this.program, union);
···
// Apply @default decorator if present
const rawDefault = getDefault(this.program, union);
const defaultValue = this.processDefaultValue(rawDefault);
528
-
let defWithDefault = { ...unionDef };
538
+
let defWithDefault: LexInteger = { ...unionDef as LexInteger };
if (defaultValue !== undefined) {
if (typeof defaultValue === "number") {
···
// Check for default value: property default takes precedence, then union's @default
let defaultValue: string | number | boolean | undefined;
if (prop?.defaultValue !== undefined) {
648
-
defaultValue = serializeValueAsJson(this.program, prop.defaultValue, prop) as any;
658
+
defaultValue = serializeValueAsJson(this.program, prop.defaultValue, prop) as string | number | boolean;
// If no property default, check union's @default decorator
const rawUnionDefault = getDefault(this.program, unionType);
···
// Check for default value: property default takes precedence, then union's @default
let defaultValue: string | number | boolean | undefined;
if (prop?.defaultValue !== undefined) {
684
-
defaultValue = serializeValueAsJson(this.program, prop.defaultValue, prop) as any;
694
+
defaultValue = serializeValueAsJson(this.program, prop.defaultValue, prop) as string | number | boolean;
// If no property default, check union's @default decorator
const rawUnionDefault = getDefault(this.program, unionType);
···
const propDefault = serializeValueAsJson(this.program, prop.defaultValue, prop);
// For union defaults that are model references, we need to resolve them for comparison
1455
-
let resolvedUnionDefault: string | number | boolean | undefined = unionDefault as any;
1465
+
let resolvedUnionDefault: string | number | boolean | undefined;
if (unionDefault && typeof unionDefault === 'object' && 'kind' in unionDefault && unionDefault.kind === 'Model') {
const ref = this.getModelReference(unionDefault as Model, true);
resolvedUnionDefault = ref || undefined;
1470
+
resolvedUnionDefault = unionDefault as string | number | boolean;
// If the union has a different default, or if the property has a default but the union doesn't, error