Closed Phamier closed 2 years ago
Thanks for opening this issue. I think this makes sense now that we supported generating TypeScript type definitions for grammars. The original type definition was intended to give some basic type information for generic action dictionaries. This would be a breaking change though.
This is now fixed on main, and will be included in the upcoming v17 release. However, you'll have to use BaseActionDict
to get the behaviour you're looking for.
import * as ohm from 'ohm-js';
import greeting, {GreetingActionDict} from './greeting.ohm-bundle';
type MapKey = Exclude<keyof GreetingActionDict<any>, keyof ohm.BaseActionDict<any>>;
const x: MapKey = 'hello';
Introduction
Hi! π
Firstly, thanks for your work on this project! π
Today I used patch-package to patch
ohm-js@16.4.0
for the project I'm working on.Problem
String mapping in type
ActionDict
breakskeyof
type operator.Example
I wanted to make a type containing actions keys of my grammar.
Instead of returning union of string literal types
keyof ActionDict<any>
returnsstring | number
. Sotype MapKeys == never
.Solution
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.