Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Duplicate declare module '@sapper/app' in src/node_modules/@sapper/index.d.ts #1602

Closed
acim opened this issue Oct 14, 2020 · 1 comment
Closed

Comments

@acim
Copy link

acim commented Oct 14, 2020

Describe the bug

When I run 'npm run dev' or "npm run build', 'src/node_modules/@sapper/index.d.ts' gets generated, but it contains double declaration of all 4 modules. Here is how the file looks like:

declare module '@sapper/app'
declare module '@sapper/server'
declare module '@sapper/service-worker'
declare module '@sapper/common'

declare module '@sapper/app' {
	export interface Redirect {
		statusCode: number
		location: string
	}

	export function goto(href: string, opts: { noscroll?: boolean, replaceState?: boolean }): Promise<void>;
	export function prefetch(href: string): Promise<{ redirect?: Redirect; data?: unknown }>;
	export function prefetchRoutes(pathnames: string[]): Promise<void>;
	export function start(opts: { target: Node }): Promise<void>;
	export const stores: () => unknown;
}

declare module '@sapper/server' {
	import { Handler, Req, Res } from '@sapper/internal/manifest-server';

	export type Ignore = string | RegExp | ((uri: string) => boolean) | Ignore[];

	export interface MiddlewareOptions {
		session?: (req: Req, res: Res) => unknown
		ignore?: Ignore
	}

	export function middleware(opts: MiddlewareOptions): Handler;
}

declare module '@sapper/service-worker' {
	export const timestamp: number;
	export const files: string[];
	export const assets: string[];
	export const shell: string[];
	export const routes: Array<{ pattern: RegExp }>;
}

declare module '@sapper/common' {
	export interface PreloadContext {
		fetch: (url: string, options?: any) => Promise<any>;
		error: (statusCode: number, message: Error | string) => void;
		redirect: (statusCode: number, location: string) => void;
	}

	export interface Page {
		host: string;
		path: string;
		params: Record<string, string>;
		query: Record<string, string | string[]>;
		error?: Error;
	}

	export interface Preload {
		(this: PreloadContext, page: Page, session: any): object | Promise<object>;
	}
}

This further causes that these 4 modules are not properly recognized. For example, if I do:

<script context="module">
	import type { Preload } from "@sapper/common";

	export const preload: Preload = async function(this, page, session) {
		const { user } = session;

		if (!user) {
			return this.redirect(302, 'login'); // TypeScript will know the type of `this` now
		}

		return { user };
	}
</script>

I get the following error:

Cannot use namespace 'Preload' as a type.ts(2709)

To Reproduce

Just run 'npm run dev' or "npm run build' and look at the 'src/node_modules/@sapper/index.d.ts' file.

Expected behavior
To generate 'src/node_modules/@sapper/index.d.ts' without this block:

declare module '@sapper/app'
declare module '@sapper/server'
declare module '@sapper/service-worker'
declare module '@sapper/common'

Information about your Sapper Installation:

  • The output of npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers
  System:
    OS: Linux 5.9 Linux Mint 20 (Ulyana)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 24.27 GB / 30.90 GB
    Container: Yes
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.13.1 - /usr/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 6.14.8 - /usr/bin/npm
  Browsers:
    Firefox: 81.0
  npmPackages:
    rollup: ^2.3.4 => 2.30.0 
    sapper: ^0.28.0 => 0.28.10 
    svelte: ^3.17.3 => 3.29.0

Severity

Blocks usage of TypeScript.

@singingwolfboy
Copy link
Contributor

I think this is already resolved by #1598 -- it's just not yet in a published release.

@acim acim closed this as completed Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants