Dojo 2 Theme | Variable for Class Name | No Index Signature

Let’s say I have a variable which takes the value of a class name.

If I say:

import * as css from '../styles/hazardhunt.m.css';

@theme(css)
export class HazardHunt extends HazardBase {
	private changes:{[index:string]:boolean}={};

	protected onClick=(evt:MouseEvent,item:string)=>{
		evt && evt.preventDefault();
		if((item in css) && !(css[item] in this.changes)) {
			...
		}
	}
}

It works, but it complains:

TS7017: Element implicitly has an ‘any’ type because type ‘typeof “[…]/src/styles/hazardhunt.m.css”’ has no index signature

What should I be doing instead?

This is because there is no index type on the generated type defs for css. So it will work at runtime but this is why the TypeScript type system is complaining. So be able to iterate over item in css, you’d probably need to cast the type to any (or perhaps unknown once we add support for TypeScript 3).