The Declarations module defines all TypeScript types and interfaces used throughout Stencil. It serves as the contract between different parts of the system and provides type safety for both internal and external APIs.
Location: src/declarations/
graph TD
subgraph "Public API"
Config[Config Types]
Components[Component Types]
JSX[JSX Types]
Testing[Testing Types]
end
subgraph "Internal API"
Compiler[Compiler Types]
Runtime[Runtime Types]
Build[Build Types]
Utils[Utility Types]
end
subgraph "External Integration"
TypeScript[TypeScript Integration]
Rollup[Rollup Plugin Types]
Node[Node.js Types]
end
The main configuration interface for Stencil projects:
Location: src/declarations/stencil-public-compiler.ts
Key interfaces:
Config- Main configuration interfaceValidatedConfig- Post-validation configuration with all required fieldsDevServerConfig- Dev server specific configurationTestingConfig- Testing configuration options
Common usage patterns:
import type { Config } from '@stencil/core';
export const config: Config = {
// Configuration options
};Component metadata and decorator types:
Location: src/declarations/stencil-public-runtime.ts
Key interfaces:
ComponentOptions- Options for@Component()decoratorPropOptions- Options for@Prop()decoratorStateOptions- Options for@State()decoratorMethodOptions- Options for@Method()decoratorEventOptions- Options for@Event()decoratorListenOptions- Options for@Listen()decoratorWatchOptions- Options for@Watch()decoratorElementOptions- Options for@Element()decorator
Location: src/declarations/stencil-public-runtime.ts
ComponentInterface- Base interface all components implementComponentWillLoad,ComponentDidLoad, etc. - Lifecycle method interfaces
Core runtime type definitions:
Location: src/declarations/stencil-private.ts
HostRef- Component instance data structureHostElement- Enhanced HTMLElement with Stencil properties
Location: src/declarations/vdom.ts
VNode- Virtual DOM node representationVNodeData- Virtual node attributes and propertiesChildType- Valid child node types
Location: src/declarations/stencil-private.ts
ComponentRuntimeMeta- Runtime component metadataComponentRuntimeMembers- Member definitionsComponentConstructor- Component constructor type
Build process type definitions:
Location: src/declarations/stencil-private.ts
BuildCtx- Build state and resultsCompilerBuildResults- Build output dataBuildConditionals- Feature flags
Location: src/declarations/stencil-private.ts
CompilerCtx- Persistent compiler stateCompilerWorkerContext- Worker thread contextModuleMap- Module tracking
Location: src/declarations/stencil-private.ts
Module- Compiled module representationComponentCompilerMeta- Component metadata during compilationComponentCompilerProperty- Property metadata
Different output target configurations:
Location: src/declarations/stencil-public-compiler.ts
OutputTarget- Base output target interfaceOutputTargetDist- Distribution output (type: 'dist')OutputTargetWww- Web app output (type: 'www')OutputTargetCustom- Custom output (type: 'custom')OutputTargetDistCustomElements- Custom elements bundleOutputTargetHydrate- SSR/hydrate appOutputTargetStats- Build statistics
JSX and element type definitions:
Location: src/declarations/jsx.ts
JSX.IntrinsicElements- HTML element typesJSX.Element- JSX element typeHTMLAttributes- HTML attribute typesDOMAttributes- DOM event handlers
Additional JSX types: src/declarations/stencil-public-runtime.ts
LocalJSX- Component-specific JSX namespaceLibraryManagedAttributes- Attribute management
Location: src/declarations/stencil-private.ts
CompilerSystem- File system abstractionLogger- Logging interfaceCache- Build cache interface
Location: src/declarations/stencil-public-compiler.ts
Diagnostic- Error/warning representationDiagnosticLevel- Error severity levelsDiagnosticMessageChain- Chained diagnostic messages
Location: src/utils/constants.ts
MEMBER_FLAGS- Bitwise flags for component membersHOST_FLAGS- Component instance state flagsVNODE_FLAGS- Virtual node type flags
Location: src/utils/constants.ts
PLATFORM_FLAGS- Platform capability flagsBUILD- Build conditionals object
Location: src/declarations/typescript.ts
- TypeScript compiler API type imports
- Custom TypeScript transformer types
Location: src/declarations/rollup.ts
- Rollup plugin interfaces
- Bundle configuration types
Location: Various declaration files import from @types/node
- File system types
- Process types
- Module types
Test framework type definitions:
Location: src/declarations/testing.ts
SpecPage- Unit test page interfaceE2EPage- E2E test page interfaceE2EElement- E2E element wrapperTestingConfig- Test configurationJestConfig- Jest configuration extensions
Runtime type checking utilities:
Location: src/utils/output-target.ts
isOutputTargetDist()isOutputTargetWww()isOutputTargetCustom()isOutputTargetHydrate()
Location: src/utils/helpers.ts
- Various type guard functions
- Type assertion utilities
- Import Types Only: Use
import typefor type-only imports - Avoid Circular Dependencies: Be careful with type imports
- Use Discriminated Unions: For type safety with variants
- Document Complex Types: Add JSDoc comments
- Prefer Interfaces: Over type aliases for object shapes
- Public API: Start in
src/declarations/stencil-public-*.ts - Internal API: Look in
src/declarations/stencil-private.ts - Component Types: Check
src/declarations/stencil-public-runtime.ts - Build Types: See
src/declarations/stencil-public-compiler.ts - Use IDE: "Go to Definition" to find actual types
When working with types:
- Check Usage: Search for all usages before changing
- Maintain Compatibility: Consider existing code
- Update Tests: Ensure type tests still pass
- Document Changes: Note breaking changes in commits
// Raw config from user
import type { Config } from '@stencil/core';
// Validated config after processing
import type { ValidatedConfig } from '../../declarations';// Build time metadata
import type { ComponentCompilerMeta } from '../../declarations';
// Runtime metadata
import type { ComponentRuntimeMeta } from '../../declarations';import type { OutputTarget } from '@stencil/core';
import { isOutputTargetDist } from '@utils';
if (isOutputTargetDist(outputTarget)) {
// TypeScript knows this is OutputTargetDist
}- Better Type Inference: Reduce need for explicit types
- Template Literal Types: For more precise string types
- Stricter Types: Remove more
anyusage - Type Generation: Auto-generate from JSON schemas
- Runtime Validation: Generate validators from types