jsii
jsii copied to clipboard
Support for parameters of type RegExp
:rocket: Feature Request
Affected Languages
- [ ]
TypeScript
orJavascript
- [x]
Python
- [x]
Java
- [x] .NET (
C#
,F#
, ...)
General Information
-
JSII Version: Any
-
Platform: any
-
[ ] I may be able to implement this feature request
-
[ ] This feature might incur a breaking change
Description
I'd like to use RegExp as input for a method:
public foo(bar: RegExp) {
...
}
Currently this seems to be impossible, I get this compile error:
node_modules/typescript/lib/lib.es5.d.ts:970:13 - error TS9999: JSII: Cannot use private type RegExp in exported declarations
970 declare var RegExp: RegExpConstructor;
This could be tricky as there may not be a RegExp
type in all programming languages... But I reckon we could vend a standard wrapper in those cases. Serialization to JSON might be another tricky thing (e.g: we need to be careful to include the modifiers, etc...).
The main pitfall however is that RegExp isn't exactly a unified standard - there are many different flavors of regexes with different capabilities, which might make it tricky to interoperate between languages in a way that is not "surprising" to users.
This would be quite a cool thing!
@RomainMuller Yes RegExp aren't a unified standard, but with JSII at least we know that the execution will be done in Node.js. That might confuse Python, Go and Java users but should be easy to document.
Do we have to provide native integration with every language's implementation? Could it mot be as simple as a class that takes a single JS compatible string?
Could it not be as simple as a class that takes a single JS compatible string?
That's effectively the same as modeling your API as accepting a string and doing new RegExp(str)
on that. In fact, things become trickier when an API returns a RegExp that the consumer is supposed to make use of (because then we'd have to cycle that to JS to ensure behavior consistency). Ultimately that starts to look oddly similar to implementing a RegExp
type fully in user-land and using that (which you don't need compiler support to do!)