Skip to content

Instantly share code, notes, and snippets.

@tpluscode
Last active October 29, 2016 07:07
Show Gist options
  • Save tpluscode/d962f5bb894392dd6f7887f07a2d5ca7 to your computer and use it in GitHub Desktop.
Save tpluscode/d962f5bb894392dd6f7887f07a2d5ca7 to your computer and use it in GitHub Desktop.
/// <reference path='typings/index.d.ts' />
import {promises as jsonld} from 'jsonld';
import {jsonLdObject, JsonLdResource} from './SampleObjects';
// this works fine, JS object literal passed directly to jsond.js
jsonld.expand({
'@context': 'http://schema.org/',
'@id': 'http://example.com/tpluscode',
'@type': 'Person',
givenName: 'Tomasz'
}).then(log);
// these two calls throw a compilation error
jsonld.expand(jsonLdObject).then(log);
jsonld.expand(new JsonLdResource()).then(log);
function log(expanded) {
console.log(JSON.stringify(expanded, null, 2));
}
{
"dependencies": {
"jsonld": "^0.4.11"
}
}
export var jsonLdObject = {
'@context': 'http://schema.org/',
'@id': 'http://example.com/tpluscode',
'@type': 'Person',
givenName: 'Tomasz'
};
export class JsonLdResource {
get '@context'() {
return 'http://schema.org';
}
get '@id'() {
return 'http://example.com/tpluscode';
}
get '@type'() {
return 'Person';
}
get givenName() {
return 'Tomasz';
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": false
},
"include": [
"index.ts"
],
"exclude": [
"typings"
]
}
{
"dependencies": {
"jsonld": "registry:npm/jsonld#0.4.0+20161023213320"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment