diff --git a/src/ts/property.ts b/src/ts/property.ts index 7cdb5e2..4b4f183 100644 --- a/src/ts/property.ts +++ b/src/ts/property.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {createArrayTypeNode, createKeywordTypeNode, createPropertySignature, createStringLiteral, createToken, createTypeReferenceNode, createUnionTypeNode, PropertySignature, SyntaxKind} from 'typescript'; +import {createArrayTypeNode, createKeywordTypeNode, createPropertySignature, createStringLiteral, createToken, createTypeOperatorNode, createTypeReferenceNode, createUnionTypeNode, PropertySignature, SyntaxKind} from 'typescript'; import {Log} from '../logging'; import {Format, ObjectPredicate, TObject, TSubject} from '../triples/triple'; @@ -108,7 +108,11 @@ export class Property { private typeNode() { const node = this.type.scalarTypeNode(); - return createUnionTypeNode([node, createArrayTypeNode(node)]); + return createUnionTypeNode([ + node, + createTypeOperatorNode( + SyntaxKind.ReadonlyKeyword, createArrayTypeNode(node)) + ]); } toNode(context: Context): PropertySignature { diff --git a/tests/baselines/comments.ts.txt b/tests/baselines/comments.ts.txt index a3c5815..a32c306 100644 --- a/tests/baselines/comments.ts.txt +++ b/tests/baselines/comments.ts.txt @@ -2,7 +2,7 @@ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; /** Names are great! {@link X Y} */ - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; /** * Things are amazing! diff --git a/tests/baselines/inheritance_multiple.ts.txt b/tests/baselines/inheritance_multiple.ts.txt index f8b7c69..7bb0ef7 100644 --- a/tests/baselines/inheritance_multiple.ts.txt +++ b/tests/baselines/inheritance_multiple.ts.txt @@ -1,5 +1,5 @@ type PersonLikeBase = ThingBase & { - "height"?: Number | Number[]; + "height"?: Number | readonly Number[]; }; export type PersonLike = { "@type": "PersonLike"; @@ -8,14 +8,14 @@ export type PersonLike = { type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = ({ "@type": "Thing"; } & ThingBase) | (PersonLike | Vehicle); type VehicleBase = ThingBase & { - "doors"?: Number | Number[]; + "doors"?: Number | readonly Number[]; }; export type Vehicle = { "@type": "Vehicle"; diff --git a/tests/baselines/inheritance_one.ts.txt b/tests/baselines/inheritance_one.ts.txt index 9707f52..ba9a34d 100644 --- a/tests/baselines/inheritance_one.ts.txt +++ b/tests/baselines/inheritance_one.ts.txt @@ -1,5 +1,5 @@ type PersonLikeBase = ThingBase & { - "height"?: Number | Number[]; + "height"?: Number | readonly Number[]; }; export type PersonLike = { "@type": "PersonLike"; @@ -8,7 +8,7 @@ export type PersonLike = { type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = ({ "@type": "Thing"; diff --git a/tests/baselines/quantities.ts.txt b/tests/baselines/quantities.ts.txt index f7c1a22..0cb2b72 100644 --- a/tests/baselines/quantities.ts.txt +++ b/tests/baselines/quantities.ts.txt @@ -31,7 +31,7 @@ export type Quantity = ({ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = ({ "@type": "Thing"; diff --git a/tests/baselines/simple.ts.txt b/tests/baselines/simple.ts.txt index 1e38e0d..dc36a70 100644 --- a/tests/baselines/simple.ts.txt +++ b/tests/baselines/simple.ts.txt @@ -1,7 +1,7 @@ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = { "@type": "Thing"; diff --git a/tests/baselines/sorted_props.ts.txt b/tests/baselines/sorted_props.ts.txt index 0e6cfa8..89c75bd 100644 --- a/tests/baselines/sorted_props.ts.txt +++ b/tests/baselines/sorted_props.ts.txt @@ -1,10 +1,10 @@ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "a"?: Text | Text[]; - "b"?: Text | Text[]; - "c"?: Text | Text[]; - "d"?: Text | Text[]; + "a"?: Text | readonly Text[]; + "b"?: Text | readonly Text[]; + "c"?: Text | readonly Text[]; + "d"?: Text | readonly Text[]; }; export type Thing = { "@type": "Thing"; diff --git a/tests/baselines/sorted_proptypes.ts.txt b/tests/baselines/sorted_proptypes.ts.txt index e621e44..5eca524 100644 --- a/tests/baselines/sorted_proptypes.ts.txt +++ b/tests/baselines/sorted_proptypes.ts.txt @@ -1,7 +1,7 @@ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "a"?: (Boolean | Date | DateTime | Number | Text | Time) | (Boolean | Date | DateTime | Number | Text | Time)[]; + "a"?: (Boolean | Date | DateTime | Number | Text | Time) | readonly (Boolean | Date | DateTime | Number | Text | Time)[]; }; export type Thing = { "@type": "Thing"; diff --git a/tests/baselines/stringlike_http.ts.txt b/tests/baselines/stringlike_http.ts.txt index 5621138..005de8a 100644 --- a/tests/baselines/stringlike_http.ts.txt +++ b/tests/baselines/stringlike_http.ts.txt @@ -4,17 +4,17 @@ export type EntryPoint = ({ } & EntryPointBase) | string; type OrganizationBase = ThingBase & { - "locatedIn"?: Place | Place[]; - "owner"?: Person | Person[]; - "urlTemplate"?: URL | URL[]; + "locatedIn"?: Place | readonly Place[]; + "owner"?: Person | readonly Person[]; + "urlTemplate"?: URL | readonly URL[]; }; export type Organization = ({ "@type": "Organization"; } & OrganizationBase) | string; type PersonBase = ThingBase & { - "height"?: Quantity | Quantity[]; - "locatedIn"?: Place | Place[]; + "height"?: Quantity | readonly Quantity[]; + "locatedIn"?: Place | readonly Place[]; }; export type Person = ({ "@type": "Person"; @@ -33,7 +33,7 @@ export type Quantity = ({ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = ({ "@type": "Thing"; diff --git a/tests/baselines/stringlike_https.ts.txt b/tests/baselines/stringlike_https.ts.txt index 5621138..005de8a 100644 --- a/tests/baselines/stringlike_https.ts.txt +++ b/tests/baselines/stringlike_https.ts.txt @@ -4,17 +4,17 @@ export type EntryPoint = ({ } & EntryPointBase) | string; type OrganizationBase = ThingBase & { - "locatedIn"?: Place | Place[]; - "owner"?: Person | Person[]; - "urlTemplate"?: URL | URL[]; + "locatedIn"?: Place | readonly Place[]; + "owner"?: Person | readonly Person[]; + "urlTemplate"?: URL | readonly URL[]; }; export type Organization = ({ "@type": "Organization"; } & OrganizationBase) | string; type PersonBase = ThingBase & { - "height"?: Quantity | Quantity[]; - "locatedIn"?: Place | Place[]; + "height"?: Quantity | readonly Quantity[]; + "locatedIn"?: Place | readonly Place[]; }; export type Person = ({ "@type": "Person"; @@ -33,7 +33,7 @@ export type Quantity = ({ type ThingBase = { /** IRI identifying the canonical address of this object. */ "@id"?: string; - "name"?: Text | Text[]; + "name"?: Text | readonly Text[]; }; export type Thing = ({ "@type": "Thing";