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.

Support symbol properties on namespaces

See original GitHub issue

Search Terms

  • namespace symbol
  • namespace symbol property
  • namespace symbol properties

Suggestion

The ability to declare symbol properties on TypeScript namespaces.

Use Cases

See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/42154#discussion_r376739320.

Examples

// doSomething.d.ts
import { promisify } from "util";

declare function doSomething(
	foo: any,
	onSuccessCallback: (result: string) => void,
	onErrorCallback: (reason: any) => void
);
declare namespace doSomething {
	function [promisify.custom](foo: any): Promise<string>;
}

export = doSomething;

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielRosenwassercommented, Feb 15, 2020

Seems like this is mostly meant for the .d.ts representations - is that the intent? Because otherwise, you can already add computed properties to functions.

function blah() {

}

blah[Symbol.iterator] = 100;

One problem that @weswigham brought up with this is that assuming you’re repurposing let/const/var to export these symbols, it would introduce a parsing ambiguity.

export namespace foo {
  export let [xyz] = 10; // currently parses as a binding pattern
}
0reactions
weswighamcommented, Dec 1, 2020

We could allow it only in ambient contexts, but that has the possibility of stepping on whatever tc39 might do to allow symbol-named module members natively.

😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Namespaces - cppreference.com
Symbols declared inside a namespace block are placed in a named scope that prevents them from being mistaken for identically-named symbols ...
Read more >
IPropertySymbol Interface (Microsoft.CodeAnalysis)
Properties ; ContainingNamespace. Gets the INamespaceSymbol for the nearest enclosing namespace. Returns null if the symbol isn't contained in a namespace. ( ...
Read more >
Symbol - JavaScript - MDN Web Docs
Chrome Edge Symbol Full support. Chrome38. Toggle history Full support. Edge12. footnote... @@toPrimitive Full support. Chrome47. Toggle history Full support. Edge15. Toggle... Symbol() constructor Full support....
Read more >
Symbol Class Properties
ControlTemplate, Gets or sets the control template used for this symbol. public Property, DependencyObjectType, (Inherited from System.Windows.
Read more >
Compiler error "cannot resolve symbol" with nested ...
BasicFolders.Properties { using System;. without the nasty duplicate. It's still an open question on how this happened.
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