GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Allow dynamic names in types by rbuckton · Pull Request #15473 · microsoft/TypeScript Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||
| interface T16 { | ||
| [c5]: number; | ||
| [c6]: string; |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be an error? I also tested with duplicate string literals with incompatible types. I expected a compile time error, however a union may also be possible.
const k1 = "literal name"; const k2 = "literal name"; interface T17 { [k1]: string; [k2]: 123; // error expected } type T18 = { [k1]: string; [k2]: 123; // error expected } // strange IntelliSense: // type T18 = { literal name: string } interface T19 { ['literal name']: string; ['literal name']: 123; // error as expected } interface T20 { ['literal name']: string; // error here [k1]: 123; // and also here } let t17: T17; t17['literal name'] // strange IntelliSense: `T17.literal name: string` let t19: T19; t19['literal name'] // strange IntelliSense: `T19[['literal name']]: string`
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Can you give an example of the symbol literal type scenario? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The code looks solid enough, but I don't really get why this change is needed right now. It seems like a lot of change without much payoff. Maybe this should wait until we have symbol literal types?
Also a few nitpicks in the comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,102 @@ | |||
| // @target: esnext | |||
| // @module: commonjs | |||
| // @filename: module.ts | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
can you add // @declaration: true here to test the declarationEmitter code?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (name) { | ||
| // TODO(rbuckton): ESSymbolLiteral | ||
| const nameType = checkComputedPropertyName(name); | ||
| return (nameType.flags & TypeFlags.StringOrNumberLiteral) !== 0; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I personally find !! easier to read than !== 0, but I'm not sure how common that is..
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it has a major impact on performance, but !! requires coercion from SMI to boolean, while !== 0 does not.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| function resolveDynamicMembersOfClassOrInterfaceOrTypeLiteralNode(node: ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode, symbolTable: SymbolTable) { | ||
| for (const member of node.members) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it would be simpler to have a third parameter symbol and only one resolveDynamicMembersOfNode(members: NodeArray<ClassElement | TypeElement | ObjectLiteralElementLike>, symbols: Symbol[], symbolTable: SymbolTable). Then resolveDynamicMembersOfSymbol could pull off the properties of node in each case.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The PR has been updated to include unique symbol types. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
255ff27 to
57674dd
Compare
|
Updated with support for unique symbol types. Also updated the description, above. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
At some point we may choose to simplify the binder with respect to well-known symbols and let late-binding take care of it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nathan Shively-Sanders (@sandersn) any other comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg), Mohamed Hegazy (@mhegazy): In ae11ae5 I've made some changes to how we handle widening in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
can I use without use "// ts-ignore" instruction to make the compiler ignore that "mistake"? for example: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Daniel Rosenwasser (@DanielRosenwasser) Can we add it to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Herrington Darkholme (@HerringtonDarkholme) we are updating the docs currently. we should have them all up-to-date before the final 2.7 goes out next week. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Proposal: a literal notation for well-known symbols Better typing support for ES2015 symbols Symbols as literal types Support type-checking of computed properties for constants and Symbols Challenges with ES6 symbols
There was an error while loading. Please reload this page.