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

Add .d.ts files for improved TypeScript support #30

Closed
baseplate-admin opened this issue Dec 2, 2023 · 3 comments · Fixed by #33
Closed

Add .d.ts files for improved TypeScript support #30

baseplate-admin opened this issue Dec 2, 2023 · 3 comments · Fixed by #33
Assignees
Labels
enhancement New feature or request

Comments

@baseplate-admin
Copy link

Describe the problem

It would be awesome if the project supports types.d file ( or maybe rewrite in typescript? )

Otherwise it's not possible to use this project in typescript based project ( well it's possible to use @ts-ignore, but you get the idea )
`

Describe the proposed solution

The way i see it, there's 2 options

  1. Rewrite in typescript ( since project already uses jsdoc, it should be easier )
  2. Add types files ( this is the approach that requires the least amount of work )

Alternatives considered

Ignoring types in typescript file

Importance

would make my life easier

@baseplate-admin baseplate-admin added the enhancement New feature or request label Dec 2, 2023
@patricknelson
Copy link
Owner

Already supports TypeScript, the lib just isn't written in it. That said: I do not plan on ever converting this library to TypeScript, at least not for now. My reasoning is aligned with that of the Svelte framework itself, which does the same thing (see here for a good article on that topic).

And for option 2 can you be more specific on what you're proposing? It may be because I'm relatively new to TypeScript, but I can say that I'm using svelte-retag inside of a TypeScript project already and the Intellisense and linting (in IDE at least) are working well. See below.

Also, please feel free to submit a PR as well!

image

@baseplate-admin
Copy link
Author

baseplate-admin commented Dec 2, 2023

Already supports TypeScript, the lib just isn't written in it. That said: I do not plan on ever converting this library to TypeScript, at least not for now. My reasoning is aligned with that of the Svelte framework itself, which does the same thing (see here for a good article on that topic).

Fair enough, then something along the line of type file would be awesome.

I'm using svelte-retag inside of a TypeScript project already and the Intellisense and linting (in IDE at least) are working well. See below.

This is awkward, vscode doesn't pick up any type definition for svelte-retag
Screenshot 2023-12-02 104922

with following tsconfig.json:

{
    "include": ["./**/*.ts", "./**/*.tsx", "django_core/static_src/components/index.ts"],
    "exclude": ["node_modules", "postcss.config.cjs", "django_core/static"],
    "compilerOptions": {
        "lib": ["esnext", "DOM", "DOM.Iterable"],
        "allowJs": true,
        "checkJs": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "moduleResolution": "Bundler",
        "module": "esnext",
        "target": "esnext",
        "ignoreDeprecations": "5.0",
        "skipLibCheck": false,
        "sourceMap": true,
        "strict": true,
        "paths": {
            "$functions": ["./django_core/static_src/functions/"],
            "$functions/*": ["./django_core/static_src/functions/*"],
            "$icons": ["./django_core/static_src/components/icons/"],
            "$icons/*": ["./django_core/static_src/components/icons/*"],
            "$components": ["./django_core/static_src/components/"],
            "$components/*": ["./django_core/static_src/components/*"]
        }
    }
}

So my proposal is to add a definition file. ( example from marked-emoji )

@patricknelson patricknelson added the help wanted Extra attention is needed label Dec 2, 2023
@patricknelson patricknelson changed the title Typescript support Add .d.ts files for improved TypeScript support Dec 3, 2023
@patricknelson patricknelson removed the help wanted Extra attention is needed label Dec 4, 2023
@patricknelson patricknelson self-assigned this Dec 4, 2023
@patricknelson
Copy link
Owner

See #33 (WIP)

This was linked to pull requests Dec 6, 2023
patricknelson added a commit that referenced this issue Dec 6, 2023
…nt a "newable" constructor type and also fixing the optional types by defining their defaults, so the generated .d.ts properly suffixes the "?" at the end of each optional field.
patricknelson added a commit that referenced this issue Dec 7, 2023
…nt a "newable" constructor type and also fixing the optional types by defining their defaults, so the generated .d.ts properly suffixes the "?" at the end of each optional field.
patricknelson added a commit that referenced this issue Dec 7, 2023
… custom type for 'component' to prevent any confusion with an actual Svelte type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants