GithubHelp home page GithubHelp logo

Comments (11)

ReazerDev avatar ReazerDev commented on May 25, 2024 14

Hi, wouldn't it be possible to just release the typings in the npm package?
This should fix this issue :)

from turbo-rails.

Jonnykoder avatar Jonnykoder commented on May 25, 2024 3

Has anyone solved this issue? I'm having the similar problem on rails 7.

from turbo-rails.

javan avatar javan commented on May 25, 2024

Can you share a sample app or your relevant TypeScript configuration? I can't reproduce in a stock setup on Rails 6.1:

$ rails new wired && \
  cd wired && \
  bin/rails webpacker:install:typescript && \
  yarn add @hotwired/turbo-rails && \
  rm -rf app/javascript/packs/* && \
  echo "import { Turbo, cable } from \"@hotwired/turbo-rails\"" > app/javascript/packs/application.ts && \
  echo "console.log({ Turbo, cable })" >> app/javascript/packs/application.ts && \
  bin/webpack

…

js/application-d58c957e0d7290104479.js.map    204 KiB  application  [emitted] [dev]        application
                             manifest.json  364 bytes               [emitted]              
Entrypoint application = js/application-d58c957e0d7290104479.js js/application-d58c957e0d7290104479.js.map
[./app/javascript/packs/application.ts] 102 bytes {application} [built]

from turbo-rails.

szTheory avatar szTheory commented on May 25, 2024

Thanks javan. If you add "strict": true to tsconfig.json then run tsc it produces the error. It looks like webpacker transpiles the TypeScript to JS but doesn't run the type checker itself.

from turbo-rails.

javan avatar javan commented on May 25, 2024

I see. So this is more of a feature request to add TypeScript declarations than an issue since you'd encounter the same problem trying to use any library published without types. Noted! In the meantime, you may find some of these workarounds helpful.

from turbo-rails.

szTheory avatar szTheory commented on May 25, 2024

Well it used to work in Turbolinks 6 so this is new behavior after upgrading by following the install instructions in the readme but I see your point. Regardless of how you classify it I'm sure a lot of TypeScript users would appreciate type definitions on the interface to help migrate to the new version. Thanks again for looking into this.

from turbo-rails.

javan avatar javan commented on May 25, 2024

We do have definitions for Turbo itself, which is written in TypeScript, and passes right through this package:

export * as Turbo from "@hotwired/turbo"
It would be pretty straightforward to re-export its types too along with a few manual definitions for:
export async function getConsumer() {
if (consumer) return consumer
const { createConsumer } = await import("@rails/actioncable/src")
return setConsumer(createConsumer())
}
export function setConsumer(newConsumer) {
return consumer = newConsumer
}
export async function subscribeTo(channel, mixin) {
const { subscriptions } = await getConsumer()
return subscriptions.create(channel, mixin)
}

Happy to accept a PR if anyone feels like taking that on!

from turbo-rails.

mockdeep avatar mockdeep commented on May 25, 2024

Depending on how deeply you're using Turbo, you can define your own types for your specific use cases. In our case, for the moment, we only disabling Drive, so this worked for us:

// app/javascript/@types/turbo.d.ts
declare module '@hotwired/turbo-rails' {
  type TurboSession = {
    drive: boolean;
  }

  type Turbo = {
    session: TurboSession;
  }

  export const Turbo: Turbo;
}

from turbo-rails.

kzkn avatar kzkn commented on May 25, 2024

I have opened two pullreqs to resolve this issue:

In order to keep up with turbo updates, I thought it would be preferable to convert turbo-rails to TypeScript as well.
If it is too much to convert turbo-rails to TypeScript, I think it would be better to follow the TypeScript community's practice and publish the type information from DT.

What do you think?

If there is a lightweight way to re-export just the type information from turbo-rails without converting to TypeScript, that would be fine too.

from turbo-rails.

paulorivera27 avatar paulorivera27 commented on May 25, 2024

+1 on this one..

from turbo-rails.

kzkn avatar kzkn commented on May 25, 2024

I've opened #392 about ten months ago. Please upvote 😄

from turbo-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.