Skip to content

4.3: as const looking for the identifier const in a generic class #44292

@orta

Description

@orta

Bug Report

We got a report that as const stopped being special case syntax from NordicSemiconductor/cloud-e2e-bdd-test-runner-js#188

🔎 Search Terms

as const 4.3 Cannot find name 'const'

🕗 Version & Regression Information

  • This changed between versions 4.2 and 4.3

⏯ Playground Link

type Store = { a: 123 }
export type Cleaner = <W extends Store>(runner: FeatureRunner<W>) => Promise<any>

export class FeatureRunner<W extends Store> {
	private readonly cleaners: Cleaner[] = []

	async runFeature(): Promise<any> {
		const objectWhichShouldBeConst = {
			flags: {},
			settings: {},
		} as const

//  ERR: Cannot find name 'const'.
	
		return objectWhichShouldBeConst
	}

	async run(): Promise<any> {
		const result = {}
		// Removing this line gets rid of the error above
		this.cleaners.forEach(c => c(this))
		return result
	}
}

Workbench Repro

🙁 Actual behavior

Compiler error from bad lookup for const

🙂 Expected behavior

No error

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions