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 for the realworld example #89

Open
UnlimitedCookies opened this issue May 27, 2021 · 7 comments
Open

Typescript for the realworld example #89

UnlimitedCookies opened this issue May 27, 2021 · 7 comments

Comments

@UnlimitedCookies
Copy link

UnlimitedCookies commented May 27, 2021

This would make it easier for beginners who want to use Svelte(kit) alongside typescript and need a starting point for all the necessary type declarations. I've tried to add some, but gave up at some point.

It is a selling point for svelte if you see the realworld example and can already get an idea how to use it.

We all know Svelte <3 TypeScript.

I think this would especially please @orta

@SuspiciousLookingOwl
Copy link

SuspiciousLookingOwl commented May 27, 2021

IMO writing the realworld example in TypeScript is not really a good idea since it might confuse some developers who don't know TypeScript, while if the realworld example is written in JavaScript, it can be understood by both JavaScript and TypeScript developer.

Plus you can find TypeScript example on doc easily, for example typings for load function can be found here

	/**
	 * @type {import('@sveltejs/kit').Load}
	 * or import type { Load } from "@sveltejs/kit";
	 */
	export async function load({ page, fetch, session, context }) {
		const url = `/blog/${page.params.slug}.json`;
		const res = await fetch(url);

		if (res.ok) {
			return {
				props: {
					article: await res.json()
				}
			};
		}

		return {
			status: res.status,
			error: new Error(`Could not load ${url}`)
		};
	}

@jhubbardsf
Copy link

I don't see why a Typescript SvelteKit realworld example can't coexistent with this one. No reason there can't be both. But that might be out of scope of this issue section.

@matjam
Copy link

matjam commented Dec 16, 2022

I'm trying to use best practices learning Sveltekit using TypeScript and it's really hard to follow the documentation without a working example in TypeScript to know exactly where to define types and how to pass them around. I'm getting extremely frustrated as I'm a BE dev trying to dabble in Svelte to build UIs for my BE services and this has been my general experience with Javascript projects.

Everyone who KNOWS js and ts well just instantly understand everything because all the docs are written by people who assume everyone has the same context as them. But in reality, people need full working examples, with clear explanation of what things do in the frame work.

As it stands it's not obvious how any of this works in Typescript.

@matjam
Copy link

matjam commented Dec 17, 2022

OK, so after spending a little time figuring things out (and getting help from colleagues) I figured out what I was doing wrong, and I wrote an example TypeScript app that people can look at if they stumble on this issue.

If someone is keen to start work on a TypeScript version of the Realworld app, let me know. I could probably help with some of it.

Pro tip: toggling on TS versions of the docs is super helpful.

@AntoineBalaine
Copy link

Hello,
I’ve ported the real-world app to Svelte Typescript.

It’s basically the same code, I just pulled the types from the api using openapi-typescript, added unit and E2E tests, and stewed the folder the structure a little differently.
Porting to typescript was a great way of learning Svelte, and I couldn’t have done it without this repo. So, thank you very much for writing the JS version of this app!

I did my best to write detailed commit messages, too.
I hope this helps. Here’s the repo.

@matjam
Copy link

matjam commented Jan 11, 2023

Hello, I’ve ported the real-world app to Svelte Typescript.

Ha! Thank you - yet again proof that if you procrastinate long enough, someone else will scratch your itch :D

@weebao
Copy link

weebao commented Oct 24, 2024

Second this need for a typescript sample for this repo

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

No branches or pull requests

6 participants