Closed drewmw5 closed 2 years ago
As you can see at https://w3c.github.io/web-nfc/#data-mapping, recordType
can be any string that follows a certain pattern (See local type and external type).
Is it possible in TypeScript to have something like below?
readonly recordType: NDEFRecordTypes | string;
or
type NDEFRecordTypes = string | "absolute-url" | "empty" | "mime" | "smart-poster" | "text" | "unknown" | "URL";
As you can see at https://w3c.github.io/web-nfc/#data-mapping,
recordType
can be any string that follows a certain pattern (See local type and external type).Is it possible in TypeScript to have something like below?
readonly recordType: NDEFRecordTypes | string;
or
type NDEFRecordTypes = string | "absolute-url" | "empty" | "mime" | "smart-poster" | "text" | "unknown" | "URL";
Ah, good to know, there's still plenty I have left to read. Thanks for that. You are correct, the following example you gave is valid TypeScript, the other one was not:
type NDEFRecordTypes = string | "absolute-url" | "empty" | "mime" | "smart-poster" | "text" | "unknown" | "URL";
Is there more to it than that?
@takefumi-yoshii Can you have a look as well?
As @beaufortfrancois mentioned earlier, record type can be a string. How would you write this example after this PR? https://w3c.github.io/web-nfc/#write-an-external-record-with-an-ndef-message-as-payload
Then, smart poster local types should also be listed?
Well, to me it seems that if we cannot add to the definitions a generic "string" as a fallback, then we should leave recordType
as string
. Static type validation as "string" should be enough, and dynamic validation, including standard record types defined by the NFC Forum, is defined by the algorithms in the spec, and it will depend on context (where the records belong).
If there are shortcomings there, please file issues.
This pull request is for adding types to recordTypes.