Skip to content

isSnippet() function #14017

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

Open
webJose opened this issue Oct 29, 2024 · 3 comments
Open

isSnippet() function #14017

webJose opened this issue Oct 29, 2024 · 3 comments

Comments

@webJose
Copy link
Contributor

webJose commented Oct 29, 2024

Describe the problem

We use a class that accepts (or tries to, at least) 3 types of content in its content property:

  • A component
  • A snippet
  • A single-spa parcel

The class used to work fine with custom isSnippet and isParcel functions. The former one was working by checking the content was an object that had a render function. This seems to have changed now. It seems that snippets are now (also?) functions.

Describe the proposed solution

Instead of us, mere mortals, having to guess what constitutes a snippet, it would be nice if Svelte provided us with an isSnippet() function that would always be accurate. Taking out the guesswork is the main concern here.

Importance

would make my life easier

@brunnerh
Copy link
Member

@webJose
Copy link
Contributor Author

webJose commented Oct 29, 2024

That would be an interesting approach, but unsure how it would play in the TypeScript world. The idea of this function is probably simpler to achieve. I just need the following from Svelte:

export function isSnippet(obj: unknown): obj is Snippet { ... }

A simple Boolean function that narrows types in TS. The idea of a single syntax for components and snippets is cool, though. I suppose it is also harder to achieve, TS-wise.

@webJose
Copy link
Contributor Author

webJose commented Nov 28, 2024

If you guys go for this (which I would love to see), may I also ask for an isComponent() function? Just to complete the set. 😄

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

2 participants