Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@types/ember-data enhancement] - DS.Store.createRecord() doesn't type check inputProperties #251

Open
ghost opened this issue Sep 4, 2018 · 3 comments
Labels
enhancement types:core:data Something is wrong with the Ember Data type definitions types:core Something is wrong with the Ember type definitions

Comments

@ghost
Copy link

ghost commented Sep 4, 2018

ember-cli: 3.3.0
node: 8.11.3
os: linux x64
TypeScript 2.9.2

My tsconfig.json

{
"compilerOptions": {
"target": "es2017",
"allowJs": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noEmitOnError": false,
"noEmit": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"module": "es6",
"paths": {
"my-app/tests/": [
"tests/
"
],
"my-app/": [
"app/
"
],
"": [
"types/
"
]
}
},
"include": [
"app",
"tests",
"types"
]
}

My tslint.json

{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"rules": {
"arrow-parens": [true, "ban-single-arg-parens"],
"cyclomatic-complexity": [true, 7],
"forin": false,
"indent": [true, "spaces", 2],
"interface-name": false,
"max-file-line-count": [true, 500],
"member-ordering": [true, {
"order": [
"public-static-field",
"public-static-method",
"public-instance-field",
"public-constructor",
"public-instance-method",
"protected-static-field",
"protected-static-method",
"protected-instance-field",
"protected-constructor",
"protected-instance-method",
"private-static-field",
"private-static-method",
"private-instance-field",
"private-constructor",
"private-instance-method"
]
}],
"no-console": false,
"no-empty": [true, ["allow-empty-catch", "allow-empty-functions"]],
"object-literal-sort-keys" : false,
"quotemark": [true, "single", "avoid-escape", "avoid-template"],
"semicolon": [true, "never"],
"trailing-comma": [true, "never"],
"variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"]
}
}

How to reproduce?

Use DS.Store.createRecord() to create a new record and pass inputProperties that don't exist on the DS.Model subclass:

this.store.createRecord('post', { attributeThatDoesNotExist: 'value' })

What did you expect to see?

Expectation is to get the same compiler errors as generated from the following code:

const post = this.store.createRecord('post')
post.setProperties({ attributeThatDoesNotExist: 'value' })

What happened instead?

There are no type errors emitted when createRecord() is called with invalid properties or with values of the incorrect type.

@mike-north
Copy link
Contributor

Fix is:

Change this
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/034c9126166528c659935f624b17b911ae5b6b15/types/ember-data/index.d.ts#L1013-L1016

            createRecord<K extends keyof ModelRegistry>(
                modelName: K,
                inputProperties?: {}
            ): ModelRegistry[K];

to

            createRecord<K extends keyof ModelRegistry>(
                modelName: K,
                inputProperties?: Partial<SOME_UNWRAP_THING<ModelRegistry[K]>>
            ): ModelRegistry[K];

This might mean we should expose some of @types/ember's utility types via a ghost module so that they may be consumed in libs like @types/ember-data.

@mike-north mike-north changed the title [bug] - DS.Store.createRecord() doesn't type check inputProperties [@types/ember-data bug] - DS.Store.createRecord() doesn't type check inputProperties Sep 6, 2018
@mike-north mike-north added types:core Something is wrong with the Ember type definitions enhancement labels Sep 6, 2018
@mike-north mike-north changed the title [@types/ember-data bug] - DS.Store.createRecord() doesn't type check inputProperties [@types/ember-data enhancement] - DS.Store.createRecord() doesn't type check inputProperties Sep 6, 2018
@mike-north
Copy link
Contributor

flagging this as an enhancement because the request is for additional type checking that doesn't currently exist (as opposed to TS getting in the way and blocking you from doing things)

@mike-north mike-north moved this from To Do to Inbox in Ember type definitions Sep 6, 2018
@mike-north mike-north moved this from Inbox to To Do in Ember type definitions Sep 6, 2018
@chriskrycho
Copy link
Member

Leaving this open at present as I don't know whether it has changed in the interval (I don't expect so)… but the preferred path forward here is almost certainly going to be the exposing the significantly-different design path Ember Data has taken in the intervening years via types shipped from Ember Data directly.

@chriskrycho chriskrycho added the types:core:data Something is wrong with the Ember Data type definitions label Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement types:core:data Something is wrong with the Ember Data type definitions types:core Something is wrong with the Ember type definitions
Development

No branches or pull requests

2 participants