question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript namespaces to be considered?

See original GitHub issue

After some initial bickering that Typescript support does not include this and that I’ve decided to give it a try. Unfortunately, I’ve stumbled upon a big obstacle.

I am using graphql-code-generator package to generate strong types for my GraphQL queries. In the essence, it generates types like this.

export namespace GLogoutWidget {
  export type Variables = {
    id: string
  }

  export type Query = {
    __typename?: 'Query'
    user: User
  }

  export type User = {
    __typename?: 'User'
    id: string
    firstName?: string | null
    lastName?: string | null
  }
}

Usage of namespaces in this is extremely helpful as it clearly separates types for each query/mutation. Compared to apollo-codegen which outputs extremely long and annoying names for types, this is a clear win.

I would like to know if namespace support is such a huge technical problem that it cannot be included. I mean when bundling the app it should be mostly about stripping type information and let the TypeScript worry about type checking. I am kinda lost why such a decision has been made to have a separate TypeScript parser that’s limited like this.

/cc @Timer

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
danielkczcommented, Oct 31, 2018

@Timer As it was said a linked babel issue, I wasn’t able to find any information about why are namespaces legacy. Later in that discussion, it’s revealed that it’s more of a technical issue than a problem of being deprecated. I can live what that, but let’s not spread the false accusations here 😃

@brunolemos Thanks for the tip, but I’ve already switched back to TS fork and don’t want to spend time on this anymore. It’s kinda a shame. In a sense, I was looking into being able to tap into Babel world while using TypeScript without extra hassle, but this is too much blocker for me.

0reactions
arackafcommented, Oct 31, 2018

namespace are not supported on @babel/preset-typescript

Seems like that should just about settle this issue. Either convince the Babel folks to support this, or shoot me a PR over at customize-cra adding the ts-loader, and removing the current Babel solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Namespaces - TypeScript
This post outlines the various ways to organize your code using namespaces (previously “internal modules”) in TypeScript. As we alluded in our note...
Read more >
How To Use Namespaces in TypeScript | DigitalOcean
Namespaces allow the developer to create separate organization units that can be used to hold multiple values, like properties, classes, types, ...
Read more >
TypeScript Namespaces - TutorialsTeacher
The namespace is used for logical grouping of functionalities. A namespace can include interfaces, classes, functions and variables to support a single or...
Read more >
Organizing TypeScript code using namespaces
In TypeScript, namespaces are defined using the namespace keyword followed by a name of choice. ... As we can see, TypeScript namespaces are...
Read more >
TypeScript - Namespaces - Tutorialspoint
TypeScript - Namespaces, A namespace is a way to logically group related code. This is inbuilt into TypeScript unlike in JavaScript where variables ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found