generated from florian-lefebvre/astro-integration-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Simplify emitted declarations for dependent integrations
- Loading branch information
Showing
3 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
"astro-integration-kit": patch | ||
--- | ||
|
||
Simplify emitted declarations for dependent integrations. | ||
|
||
Previoysly an integration using AIK and publishing to NPM with their type declarations would generate a type like this: | ||
|
||
```ts | ||
declare const _default: (options?: undefined) => astro.AstroIntegration & { | ||
hooks: { | ||
"astro:config:setup": (params: { | ||
config: astro.AstroConfig; | ||
command: "dev" | "build" | "preview"; | ||
isRestart: boolean; | ||
updateConfig: ( | ||
newConfig: DeepPartial<astro.AstroConfig> | ||
) => astro.AstroConfig; | ||
addRenderer: (renderer: astro.AstroRenderer) => void; | ||
addWatchFile: (path: string | URL) => void; | ||
injectScript: (stage: astro.InjectedScriptStage, content: string) => void; | ||
injectRoute: (injectRoute: astro.InjectedRoute) => void; | ||
addClientDirective: (directive: astro.ClientDirectiveConfig) => void; | ||
addDevOverlayPlugin: (entrypoint: string) => void; | ||
addDevToolbarApp: (entrypoint: string | astro.DevToolbarAppEntry) => void; | ||
addMiddleware: (mid: astro.AstroIntegrationMiddleware) => void; | ||
logger: astro.AstroIntegrationLogger; | ||
}) => void; | ||
}; | ||
addExtraPage: (page: string) => void; | ||
}; | ||
``` | ||
|
||
Such inlining of the Astro hook parameter types not only makes your published package include unnecessary code, but can also make it fail to compile if you use a hook that inlines a reference to a transitive dependency: | ||
|
||
``` | ||
error TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/[email protected]_@[email protected]/node_modules/vite'. This is likely not portable. A type annotation is necessary. | ||
``` | ||
|
||
Now, the same integration will emit the following simplified declaration, without inlining any of the AstroHooks types: | ||
|
||
```ts | ||
declare const _default: (options?: undefined) => astro.AstroIntegration & { | ||
addExtraPage: (page: string) => void; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters