sveltejs / sapper-template

Starter template for Sapper apps
703 stars 214 forks source link

[help-needed] Rollup TypeScript support #252

Closed martonlederer closed 4 years ago

martonlederer commented 4 years ago

This pull request contains a script to set up TypeScript with Rollup (there are some bugs, so help is needed). It would make sense to merge this after #1402 and would also solve my issue #251

benmccann commented 4 years ago

We should bump the version number in package.json to the latest (0.28.4). The type definitions were added in 0.28.1 and make using TypeScript with Sapper easier to setup

Steakeye commented 4 years ago

I'm just gonna leave this here in case you'd like to see how I wrote mine a couple of weeks ago https://gist.github.com/Steakeye/59db68c59e8fffba788f9de47f12c2ce

Steakeye commented 4 years ago

Also, my sapper typings, not sure where I lifted them from but they are as follows

///typings/@sapper/index.d.ts
declare module '@sapper/app' {
    // from sapper/runtime/src/app/types.ts
    // sapper doesn't export its types yet
    interface Redirect {
        statusCode: number
        location: string
    }
    // end

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

    export { goto, prefetch, prefetchRoutes, start, stores }
}

declare module '@sapper/server' {
    interface MiddlewareOptions {
        session?: (req: Express.Request, res: Express.Response) => unknown
        ignore?: unknown
    }

    function middleware(opts?: MiddlewareOptions): Express.RequestHandler

    export { middleware }
}

declare module '@sapper/service-worker' {
    const timestamp: number
    const files: string[]
    const shell: string[]
    const routes: { pattern: RegExp }[]

    export { timestamp, files, files as assets, shell, routes }
}
benmccann commented 4 years ago

The types are already included in Sapper. The template doesn't need to provide them

benmccann commented 4 years ago

Closing in favor of https://github.com/sveltejs/sapper-template/pull/262. Thanks for getting the ball rolling!