Skip to content

Commit 01dc94d

Browse files
authored
fix: Parse.Object.createWithoutData doesn't preserve object subclass (#2907)
1 parent 0a064e4 commit 01dc94d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/ParseObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,7 @@ class ParseObject<T extends Attributes = Attributes> {
18771877
* @static
18781878
* @returns {Parse.Object} A Parse.Object reference.
18791879
*/
1880-
static createWithoutData(id: string): ParseObject {
1880+
static createWithoutData<T extends ParseObject>(this: new (...args: any[]) => T, id: string): T {
18811881
const obj = new this();
18821882
obj.id = id;
18831883
return obj;

types/ParseObject.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ declare class ParseObject<T extends Attributes = Attributes> {
894894
* @static
895895
* @returns {Parse.Object} A Parse.Object reference.
896896
*/
897-
static createWithoutData(id: string): ParseObject;
897+
static createWithoutData<T extends ParseObject>(this: new (...args: any[]) => T, id: string): T;
898898
/**
899899
* Creates a new instance of a Parse Object from a JSON representation.
900900
*

types/tests.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ async function test_object() {
4242
// Create a new instance of that class.
4343
const gameScore = new GameScore();
4444

45+
// Expect that `createWithoutData` returns the types for the same classes (not generic ParseObjects)
46+
// $ExpectType Game
47+
Game.createWithoutData('someid');
48+
// $ExpectType GameScore
49+
GameScore.createWithoutData('scoreid');
50+
// $ExpectType ParseUser<Attributes>
51+
Parse.User.createWithoutData('someuser');
52+
4553
gameScore.set('score', 1337);
4654
gameScore.set('playerName', 'Sean Plott');
4755
gameScore.set('cheatMode', false);
@@ -2375,4 +2383,3 @@ function testInitialize() {
23752383
// Node - 1 param (should also work since javaScriptKey is optional in node)
23762384
ParseNode.initialize('appId');
23772385
}
2378-

0 commit comments

Comments
 (0)