Home / Function/ typeForCollection() — astro Function Reference

typeForCollection() — astro Function Reference

Architecture documentation for the typeForCollection() function in types-generator.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  9450af48_94b5_71a2_6795_b9b190df4757["typeForCollection()"]
  eca81928_a18b_c02e_8e5a_0440befa1a98["types-generator.ts"]
  9450af48_94b5_71a2_6795_b9b190df4757 -->|defined in| eca81928_a18b_c02e_8e5a_0440befa1a98
  453daca9_4232_0b6c_8607_0e08e829d051["writeContentFiles()"]
  453daca9_4232_0b6c_8607_0e08e829d051 -->|calls| 9450af48_94b5_71a2_6795_b9b190df4757
  83cca5af_575c_63ed_977c_458c743a8a6a["getCreateSchemaResult()"]
  9450af48_94b5_71a2_6795_b9b190df4757 -->|calls| 83cca5af_575c_63ed_977c_458c743a8a6a
  style 9450af48_94b5_71a2_6795_b9b190df4757 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/content/types-generator.ts lines 402–427

async function typeForCollection<T extends keyof ContentConfig['collections']>(
	collection: ContentConfig['collections'][T] | undefined,
	collectionKey: T,
): Promise<{ type: string; injectedType?: InjectedType }> {
	if (collection?.schema) {
		return { type: `InferEntrySchema<${collectionKey}>` };
	}
	if (!collection?.type || typeof collection.loader === 'function' || !collection.loader) {
		return { type: 'any' };
	}
	if (typeof collection.loader === 'object' && collection.loader.schema) {
		return { type: `InferLoaderSchema<${collectionKey}>` };
	}
	const result = await getCreateSchemaResult(collection, collectionKey);
	if (!result) {
		return { type: 'any' };
	}
	const base = `loaders/${collectionKey.slice(1, -1)}`;
	return {
		type: `import("./${base}.js").Entry`,
		injectedType: {
			filename: `${base}.ts`,
			content: result.types,
		},
	};
}

Subdomains

Frequently Asked Questions

What does typeForCollection() do?
typeForCollection() is a function in the astro codebase, defined in packages/astro/src/content/types-generator.ts.
Where is typeForCollection() defined?
typeForCollection() is defined in packages/astro/src/content/types-generator.ts at line 402.
What does typeForCollection() call?
typeForCollection() calls 1 function(s): getCreateSchemaResult.
What calls typeForCollection()?
typeForCollection() is called by 1 function(s): writeContentFiles.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free