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 — Support relations and inference between template literal types by ahejlsberg · Pull Request #43361 · microsoft/TypeScript Conversation
Member
With this PR we support relations and inference between template literal types. Specifically, when the target side in a type relation is a template literal type, the source side is now permitted to be a compatible (i.e. more specific) template literal type. Likewise, when inferring to a template literal target type, we now permit the source type to also be a template literal type. Some examples of improved assignment relations: declare let s1: `${number}-${number}-${number}`; declare let s2: `1-2-3`; declare let s3: `${number}-2-3`; declare let s4: `1-${number}-3`; declare let s5: `1-2-${number}`; declare let s6: `${number}-2-${number}`; s1 = s2; s1 = s3; s1 = s4; s1 = s5; s1 = s6; With this PR all of the above assignments are permitted, where previously only the first assignment was permitted. Some examples of inference between template literal types: declare function foo1<V extends string>(arg: `*${V}*`): V; function test<T extends string>(s: string, n: number, b: boolean, t: T) { let x1 = foo('*hello*'); // "hello" let x2 = foo('**hello**'); // "*hello*" let x3 = foo(`*${s}*` as const); // string let x4 = foo(`*${n}*` as const); // `${number}` let x5 = foo(`*${b}*` as const); // "true" | "false" let x6 = foo(`*${t}*` as const); // `${T}` let x7 = foo(`**${s}**` as const); // `*${string}*` }
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some sort of comment (an overview of the algorithm / what it's trying to do, or the name of it if this is a well-known one?) seems justified here
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think if you could just explain with examples too, that'd be helpful.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll add some comments.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be useful to have a singleton
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the single-element
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| ||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |