Hey there, I have a relatively simple function defined in FSL, which is causing a few type errors that I’m having trouble fixing.
I’d like to provide either an Asset
, Incident
or null
to the function, and have it return an array of documents of different possible types.
function fetchRelatedDocs(doc: Ref<Asset> | Ref<Incident> | null): Array<DocumentDef> {
if (doc == null) {
[]
}
else {
let coll = doc!.coll
let id = doc!.id
[]
}
}
There are several errors this short block throws:
cause: Type `null` does not have field `coll`
› at functions/lib/fetchRelatedDocs.fsl:100:25
› |
› 100 | let coll = doc!.coll
› | ^^^^
› |
› hint: Type `null` inferred here
› |
› 95 | function fetchRelatedDocs(doc: Ref<Asset> | Ref<Incident> | null): Array<DocumentDef> {
› | ^^^^
› |
› cause: Type `null` does not have field `id`
› at functions/lib/fetchRelatedDocs.fsl:101:23
› |
› 101 | let id = doc!.id
› | ^^
› |
› hint: Type `null` inferred here
› |
› 95 | function fetchRelatedDocs(doc: Ref<Asset> | Ref<Incident> | null): Array<DocumentDef> {
› | ^^^^
› |
› cause: Type `{ owner: Ref<User>, name: String, id: ID, ts: Time, ttl: Time | Null }` is not a subtype of `DocumentDef`
› |
› 95 | function fetchRelatedDocs(doc: Ref<Asset> | Ref<Incident> | null): Array<DocumentDef> {
› | _^
› 96 | | if (doc == null) {
› 97 | | []
› 98 | | }
› 99 | | else {
› 100 | | let coll = doc!.coll
› 101 | | let id = doc!.id
› 102 | |
› 103 | | []
› 104 | | }
› 105 | | }
› | |_^
› |
› cause: Type `Null` is not a subtype of `DocumentDef`
› |
› 95 | function fetchRelatedDocs(doc: Ref<Asset> | Ref<Incident> | null): Array<DocumentDef> {
› | _^
› 96 | | if (doc == null) {
› 97 | | []
› 98 | | }
› 99 | | else {
› 100 | | let coll = doc!.coll
› 101 | | let id = doc!.id
› 102 | |
› 103 | | []
› 104 | | }
› 105 | | }
› | |_^
› |
A few things about this I’m not too sure I understand:
- I couldn’t find documentation for a return value that is just a Doc of any type… I’d seen
CollectionDef
before, so I guessedDocumentDef
might exist. Does it? - Is there a difference between
Ref<Asset>
andAsset
in FSL?
Interested in any guidance you can provide to help. Thanks in advance!