Giter VIP home page Giter VIP logo

Comments (5)

orta avatar orta commented on August 16, 2024 1

What I did was add:

/// <reference types="nakama-runtime" />

To the top of my index.ts file for the server, which brought in the imports without a tsconfig change.

I debated adding export = nkruntime at the end of the .d.ts in this file and then submitting those changes here which would allow for import type nkruntime from "nakama-runtime". But if all of the globals are always in the runtime, then it felt like allowing for the import is a bit unrealistic and left it at that.

from nakama-common.

novabyte avatar novabyte commented on August 16, 2024

@MarcusRiemer Happy to take on this advice. Can you explain what you mean by dangerous about adding to the typeRoots? I'm not a TypeScript export so any help is appreciated.

from nakama-common.

MarcusRiemer avatar MarcusRiemer commented on August 16, 2024

"Dangerous" in the sense of "Marcus was once bitten by a globally declared conflicting var Observable: any that some unrelated package provided and therefor forgot to import RxJS after copy and pasting stuff around which led to surprising errors at runtime".

If I understand correctly the nkruntime functions are exposed to Typescript but are implemented in Go? So they are guaranteed to be available, even though there is no visible implementation? In that case the type only imports should perfectly fit this usecase, as they are purely compile time constructs and therefore never surface in the compiled JavaScript.

from nakama-common.

MarcusRiemer avatar MarcusRiemer commented on August 16, 2024

fwiw: I ran through most of the Typescript setup process (including Rollup, excluding building via docker) with the import type { nkruntime } from "nakama-runtime"; and the hacked index.d.ts and everything seems to work fine. I was a little puzzled that everything also works with the normal import statement which is probably due to the fact that all callbacks receive the relevant instances as arguments anyway. So I guess its possible to just use a normal import, but I will see what happens if I try to do some more interesting things.

from nakama-common.

bananu7 avatar bananu7 commented on August 16, 2024

That's also how I solved it (with the old style reference)

from nakama-common.

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.