Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript complains #266

Open
PavelJacoboGonzalez opened this issue Dec 19, 2023 · 9 comments
Open

Typescript complains #266

PavelJacoboGonzalez opened this issue Dec 19, 2023 · 9 comments

Comments

@PavelJacoboGonzalez
Copy link

Hello
I'm currently implementing iconify for a small project with Sveltekit, I'm learning also Sveltekit, but when I try to use it as per documentation I'm getting following typescript error. I have checked documentation but I could not find reference to how to use iconify and typescript.

please check image below.

image

I've been following documentation for iconify + svelte and my Svelte app is using typescript.

tscondig.json

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"module": "NodeNext",
		"moduleResolution": "NodeNext",
	}
}

svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	// Consult https://kit.svelte.dev/docs/integrations#preprocessors
	// for more information about preprocessors
	preprocess: vitePreprocess(),

	kit: {
		// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
		// If your environment is not supported or you settled on a specific environment, switch out the adapter.
		// See https://kit.svelte.dev/docs/adapters for more information about adapters.
		adapter: adapter(),
		alias: {
			$root: 'src'
		}
	}
};

export default config;

Thanks so much

regards

@cyberalien
Copy link
Member

I have similar code in this repository in SvelteKit demo: https://github.com/iconify/iconify/blob/main/components-demo/sveltekit-demo/src/lib/header/Header.svelte

But I'm not seeing any errors.

Can you create a basic reproduction?

@userquin
Copy link
Collaborator

userquin commented Dec 19, 2023

try importing @iconify/svelte in src/app.d.ts: check for example unplugin-icons Svelte usage in SvelteKit, Frameworks section

@PavelJacoboGonzalez
Copy link
Author

Hello, Thanks so much for the feed back. I've installed sveltekit from scratch, I install Iconify and it's still happening.
I've created this repo. It's actually happening here: https://github.com/PavelJacoboGonzalez/iconify_test/tree/development

At first I thought it was due to Svelte for Vscode extension, but not 100% sure about it.

Thanks for feedback

Regards

@userquin
Copy link
Collaborator

@userquin
Copy link
Collaborator

@cyberalien Svelte 4 has changed the defintiion, you're using Svelte 3, for Svelte 4 you need to change to this one:
https://github.com/unplugin/unplugin-icons/blob/main/types/svelte4.d.ts#L9-L10

@cyberalien
Copy link
Member

Thanks! So I need to release new package for Svelte 4... on it.

@cyberalien
Copy link
Member

Try @iconify/svelte@next, which should install version 4.0.0-beta.2

Seems to work correctly in my tests with latest Svelte 4. I'm in process of doing more tests, but most likely will finish testing only tomorrow.

@userquin
Copy link
Collaborator

@PavelJacoboGonzalez you need to use bundler module resolution, tested in your repro with @iconify/svelte@next and VSCode and Intellij (JetBrains) working with auto complete ("@iconfy/svelte": "next" then "yarn && yarn check" after updating tsconfig.json file):

imagen

imagen

imagen

@PavelJacoboGonzalez
Copy link
Author

Awesome. Working as @userquin suggested.

"module": "ESNext",
"moduleResolution": "Bundler"

Thanks so much for support.
Really appreciate
Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants