A
arktype6mo ago
francis

vscode intellisense errors on the same type definition in some files, but not others

e.g. the following type:
const exampleType = type({
email: "string.email",
});
const exampleType = type({
email: "string.email",
});
In some files, this works fine. In others, in the exact same project, this causes the following error:
Type '"string.email"' is not assignable to type '"'string' must reference a module to be accessed using dot syntax "'.
The expected type comes from property 'email' which is declared here on type 'validateObjectLiteral<{ readonly email: "string.email"; }, {}, bindThis<{ readonly email: "string.email"; }>>'
Type '"string.email"' is not assignable to type '"'string' must reference a module to be accessed using dot syntax "'.
The expected type comes from property 'email' which is declared here on type 'validateObjectLiteral<{ readonly email: "string.email"; }, {}, bindThis<{ readonly email: "string.email"; }>>'
Any ideas for what might be going on?
6 Replies
francis
francisOP6mo ago
Aha, I think I've figured ti out. This is something to do with sveltekit's implicit typing. In +server.ts or +page.ts modules, it appears that the type import resolves to:
<const def, r = Type<inferTypeRoot<def, $>, $>>(def: validateTypeRoot<def, $>): r;
<const def, r = Type<inferTypeRoot<def, $>, $>>(def: validateTypeRoot<def, $>): r;
in arktype/out/type.d.ts In files not prefixed with a +, it resolves to namespace type { ... in arktype/out/keywords/ark.d.ts. Any suggestions for how I fix this / force the type import to be correct? ah, I think it's an interaction with the svelte language server. Disabling the svelte language extension fixes the problem.
francis
francisOP6mo ago
GitHub
language-tools/packages/svelte2tsx/src/helpers/sveltekit.ts at 0655...
The Svelte Language Server, and official extensions which use it - sveltejs/language-tools
francis
francisOP6mo ago
update, it's not related to the language server, but rather the svelte extension ts plugin.
francis
francisOP5mo ago
GitHub
Svelte extension resolves incorrect import types in kit files when ...
Describe the bug The bug appears to be in the typescript plugin for the language extension. It appears under the following conditions: you are working on a sveltekit project with sveltekit-superfor...
jacksteamdev
jacksteamdev2w ago
I've run into a similar problem with Svelte for VS Code. Quick fix was to downgrade the extension (svelte.svelte-vscode) to 108.6.1. tl;dr: If your Svelte project doesn't have a svelte.config.js file, add it. The main problem was that the Svelte VS Code extension was casting inferred ArkType types to unknown in the editor. My project was using Bun with a custom Svelte plugin to compile to JS - I didn't need a svelte.config.js file to compile to JS, however, TypeScript was acting weird in Svelte files. Downgrading the Svelte extension to ^108 got inferred types working, but I noticed that the extension was logging that it couldn't find a svelte.config.js file, so I added one with svelte-preprocess. Everything is working as expected after upgrading the Svelte extension to the latest version.
ssalbdivad
ssalbdivad7d ago
Do these problems apply even to the latest versions of ArkType? Because of similar issues I converted all symbols to string literals which I expected to resolve most stuff like this.

Did you find this page helpful?