Repository navigation
fix(lib): Fix RegExp constructor with string|RegExp and flags - #30586
Nathan Shively-Sanders (sandersn) merged 1 commit into
Conversation
|
Obviously a less band‑aid solution would be identifying constructors that can be merged and dynamically merging them for union type calls, but I don’t really know how to do that. |
|
Would you mind explaining the problem more thoroughly. Normally we discuss a change like this with an issue, but this is minor enough it might be OK just to have a thorough explanation of the problem and the fix in the PR description. |
|
Nathan Shively-Sanders (@sandersn) The issue here is that TypeScript doesn’t actually consider the two following cases equal: interface RegExpConstructor {
new (pattern: RegExp, flags?: string): RegExp;
(pattern: RegExp, flags?: string): RegExp;
new (pattern: string, flags?: string): RegExp;
(pattern: string, flags?: string): RegExp;
}interface RegExpConstructor {
new (pattern: RegExp | string, flags?: string): RegExp;
(pattern: RegExp | string, flags?: string): RegExp;
}The second one can be used with: var pattern: RegExp | string;
var regexp = RegExp(pattern, 'g');while the first one can’t. #14107 describes this in more detail. |
|
Daniel Rosenwasser (@DanielRosenwasser) do you have opinions? We need to look at the combined overload set and think about what happens if existing code starts resolving to a different overload. |
|
Nathan Shively-Sanders (@sandersn) There shouldn’t be any difference, except that my above snippet will work for projects using ES2015 or newer without needing to cast Ar do a pointless |
|
TypeScript Bot (@typescript-bot) test this |
|
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at 6f64fed. You can monitor the build here. It should now contribute to this PR's status checks. |
|
TypeScript Bot (@typescript-bot) test this |
|
Heya Nathan Shively-Sanders (@sandersn), I've started to run the extended test suite on this PR at 6f64fed. You can monitor the build here. It should now contribute to this PR's status checks. |
|
RWC and user test suites are clean. I'm surprised that we don't have coverage of this anywhere in the test suite, but it's clean too. |
Previously:
Would result in:
This fixes that.
See also: #14107
review?(Nathan Shively-Sanders (@sandersn))