solid-start: [Bug?]: The example in the docs doesn't seam to work.
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
The example in the documentation doesn’t seam to work.
declare module "@solidjs/start/server" {
interface RequestEventLocals {
myNumber: number;
someString: string;
}
}
locals property within the RequestEvent doesn’t have any types declared in global.d.ts. For example in one of the routes:
import { getRequestEvent } from 'solid-js/web'
const getMessage = cache(async () => {
'use server'
const event = getRequestEvent()
// event?.locals is not typed
return
}, 'message')
export const route = {
load: () => getMessage(),
}
and my global.d.ts has
declare module '@solidjs/start/server' {
interface RequestEventLocals {
myNumber: number
someString: string
}
}
Expected behavior 🤔
No response
Steps to reproduce 🕹
Steps:
- Create an solid-start app using one of the templates
- Declare ‘@solidjs/start/server’ within the global.d.ts file
- Try accessing
event.locals.<SOMETHING>within a route function
Context 🔦
No response
Your environment 🌎
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (9 by maintainers)
It seems like the doc is not updated yet to use the new
namespaceApp. I can write up a PR if the team wanted.I also hope to add some additional comments on my usage of this feature:
declare namespace Appinstead ofdeclare module App(like in the currenttodosmvcexample) -> LSP saysA 'namespace' declaration should not be declared using the 'module' keyword. Please use the 'namespace' keyword insteadwhen I usedeclare module Appimportwithinglobal.d.tsfile, the file turns into a module and its type become scoped/isolated. As a result, theAppnamespace loses its global-ness, and thus must be written inside adeclare global. Technically this is a standard Typescript feature, but I do think it’s helpful to document this small “trick”For example, here is my current
global.d.tsThe answer by @bhuynhdev is correct, the other fixes don’t work. The docs need an updated
@RonenEizen for me it started to work also in the
global.d.tswhen changing the/// <reference types="@solidjs/start/env" />toimport "@solidjs/start/env";(make sure to restart ts server to see the effect)I am not sure why this is the case though.