generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from JoshuaKGoldberg/readonly-modifiers-check
fix: account for mapped types without modifiers in isPropertyReadonlyInType
- Loading branch information
Showing
2 changed files
with
31 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as ts from "typescript"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { createSourceFileAndTypeChecker } from "../test/utils"; | ||
import { isPropertyReadonlyInType } from "./utilities"; | ||
|
||
describe("isPropertyReadonlyInType", () => { | ||
it("does not crash when the type is a mapped type parameter extending any", () => { | ||
const { sourceFile, typeChecker } = createSourceFileAndTypeChecker(` | ||
type MyType<T> = { | ||
[K in keyof T]: 'cat' | 'dog' | T[K]; | ||
}; | ||
type Test<A extends any[]> = MyType<A>; | ||
`); | ||
const node = sourceFile.statements.at(-1) as ts.TypeAliasDeclaration; | ||
const type = typeChecker.getTypeAtLocation(node); | ||
|
||
expect( | ||
isPropertyReadonlyInType( | ||
type, | ||
ts.escapeLeadingUnderscores("length"), | ||
typeChecker | ||
) | ||
).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters