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.

[Feature request] sort literals in .d.ts

See original GitHub issue

Search Terms

Suggestion

sort string literal in .d.ts

Use Cases

avoid string literal random change order when source code didn’t change and make code history is more easy read

in this issue thread string literal is mean => "a" | "c" | "b"

this not only happen on Record, it has chance happen at all type is auto create by typescript emit with string literal

Examples

"a" | "c" | "b" is create by typesctipt emit and some time will random change order

current .d.ts output


export declare const table_plus: Record<"a" | "c" | "b">
// "a" | "c" | "b" is random change order

in this request

sort ( use simple array.sort() ) it when output emit at .d.ts

export declare const table_plus: Record<"a" | "b" | "c">

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.

Maintainer’s note [@sandersn]: To implementers: When you implement this, be sure to sort other literal types too. Consider sorting other things, like symbol, by the order of their string representation.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sandersncommented, Jul 3, 2019

@fatcerberus This is just requesting that d.ts emit sorts the union right before printing it. It wouldn’t affect the checker itself. Should be fine, except for evil corner cases like the UnionToTuple type, which manage to export the internal ordering into another type.

@AnyhowStep but then it would be the last time???

1reaction
AnyhowStepcommented, Jul 3, 2019

Oh, right. I hecked up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 4.1
String literal types in TypeScript allow us to model functions and APIs that expect a set of specific strings. ts. function setVerticalAlignment (...
Read more >
Announcing TypeScript 4.1 Beta - Microsoft Developer Blogs
String literal types in TypeScript allow us to model functions and APIs that expect a set of specific strings. function setVerticalAlignment( ...
Read more >
Template literals (Template strings) - JavaScript | MDN
String interpolation. Without template literals, when you want to combine output from expressions with strings, you'd concatenate them using the ...
Read more >
typescript-cheatsheet - GitHub Pages
Afterwards we are able to /// <reference> the node.d.ts as shown in the namespace section, and then load the modules using import url...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
Rules ; array-callback-return. Enforce return statements in callbacks of array methods ; constructor-super. Require `super()` calls in constructors ; for-direction.
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