-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type checking support for the 'role' attribute and the 'controlsl…
…ist' attribute. This fixes #89
- Loading branch information
Showing
6 changed files
with
255 additions
and
15 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
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
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
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,28 @@ | ||
import { SimpleType, SimpleTypeUnion } from "ts-simple-type"; | ||
|
||
const PRIMITIVE_STRING_ARRAY_TYPE_BRAND = Symbol("PRIMITIVE_STRING_ARRAY_TYPE"); | ||
|
||
/** | ||
* Brands a union as a primitive array type | ||
* This type is used for the "role" attribute that is a whitespace separated list | ||
* @param union | ||
*/ | ||
export function makePrimitiveArrayType(union: SimpleTypeUnion): SimpleTypeUnion { | ||
const extendedUnion: SimpleTypeUnion = { | ||
...union | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(extendedUnion as any)[PRIMITIVE_STRING_ARRAY_TYPE_BRAND] = true; | ||
|
||
return extendedUnion; | ||
} | ||
|
||
/** | ||
* Returns if a simple type is branded as a primitive array type | ||
* @param simpleType | ||
*/ | ||
export function isPrimitiveArrayType(simpleType: SimpleType): simpleType is SimpleTypeUnion { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return simpleType.kind === "UNION" && (simpleType as any)[PRIMITIVE_STRING_ARRAY_TYPE_BRAND] === true; | ||
} |
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
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